Account for view offset in bottom sheet

Summary: Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D22887857

fbshipit-source-id: 97194737a5c7c83f0ff9b35d90608c5e7e9b6bab
This commit is contained in:
Samuel Susla 2020-08-04 01:48:52 -07:00 коммит произвёл Facebook GitHub Bot
Родитель cc0cca60c1
Коммит 22584954cd
2 изменённых файлов: 15 добавлений и 5 удалений

Просмотреть файл

@ -14,6 +14,11 @@ NS_ASSUME_NONNULL_BEGIN
- (void)attachToView:(UIView *)view;
- (void)detachFromView:(UIView *)view;
/*
* Offset of the attached view relative to the root component in points.
*/
@property (nonatomic, assign) CGPoint viewOriginOffset;
@end
NS_ASSUME_NONNULL_END

Просмотреть файл

@ -78,11 +78,16 @@ struct ActiveTouch {
};
};
static void UpdateActiveTouchWithUITouch(ActiveTouch &activeTouch, UITouch *uiTouch, UIView *rootComponentView)
static void UpdateActiveTouchWithUITouch(
ActiveTouch &activeTouch,
UITouch *uiTouch,
UIView *rootComponentView,
CGPoint rootViewOriginOffset)
{
CGPoint offsetPoint = [uiTouch locationInView:activeTouch.componentView];
CGPoint screenPoint = [uiTouch locationInView:uiTouch.window];
CGPoint pagePoint = [uiTouch locationInView:rootComponentView];
pagePoint = CGPointMake(pagePoint.x + rootViewOriginOffset.x, pagePoint.y + rootViewOriginOffset.y);
activeTouch.touch.offsetPoint = RCTPointFromCGPoint(offsetPoint);
activeTouch.touch.screenPoint = RCTPointFromCGPoint(screenPoint);
@ -95,7 +100,7 @@ static void UpdateActiveTouchWithUITouch(ActiveTouch &activeTouch, UITouch *uiTo
}
}
static ActiveTouch CreateTouchWithUITouch(UITouch *uiTouch, UIView *rootComponentView)
static ActiveTouch CreateTouchWithUITouch(UITouch *uiTouch, UIView *rootComponentView, CGPoint rootViewOriginOffset)
{
UIView *componentView = uiTouch.view;
@ -109,7 +114,7 @@ static ActiveTouch CreateTouchWithUITouch(UITouch *uiTouch, UIView *rootComponen
activeTouch.componentView = componentView;
UpdateActiveTouchWithUITouch(activeTouch, uiTouch, rootComponentView);
UpdateActiveTouchWithUITouch(activeTouch, uiTouch, rootComponentView, rootViewOriginOffset);
return activeTouch;
}
@ -197,7 +202,7 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithTarget : (id)target action : (SEL)act
- (void)_registerTouches:(NSSet<UITouch *> *)touches
{
for (UITouch *touch in touches) {
auto activeTouch = CreateTouchWithUITouch(touch, _rootComponentView);
auto activeTouch = CreateTouchWithUITouch(touch, _rootComponentView, _viewOriginOffset);
activeTouch.touch.identifier = _identifierPool.dequeue();
_activeTouches.emplace(touch, activeTouch);
}
@ -212,7 +217,7 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithTarget : (id)target action : (SEL)act
continue;
}
UpdateActiveTouchWithUITouch(iterator->second, touch, _rootComponentView);
UpdateActiveTouchWithUITouch(iterator->second, touch, _rootComponentView, _viewOriginOffset);
}
}