Skip to content

Commit 4350132

Browse files
sherginfacebook-github-bot
authored andcommitted
Fabric: Storing a pointer to a ComponentView in ActiveTouch
Summary: Surprisingly, `UITouch::view` property might be nil in some cases (the documentation does not specify in which ones), and that actually happens. That breaks the calculation of a touch position relative to a view on which the touch began. This diff implements storing the view inside ActiveTouch, so we always can access it when we need it. That's similar to how it's implemented in Paper's TouchHandler. Changelog: [Internal] Fabric-specific internal change. Reviewed By: sammy-SC Differential Revision: D18752887 fbshipit-source-id: b412047132238ab4fc265e6c4fbcfb732ed27518
1 parent 7ce8bab commit 4350132

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

React/Fabric/RCTSurfaceTouchHandler.mm

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ typedef NS_ENUM(NSInteger, RCTTouchEventType) {
5757
Touch touch;
5858
SharedTouchEventEmitter eventEmitter;
5959

60+
/*
61+
* A component view on which the touch was begun.
62+
*/
63+
__strong UIView<RCTComponentViewProtocol> *componentView = nil;
64+
6065
struct Hasher {
6166
size_t operator()(const ActiveTouch &activeTouch) const {
6267
return std::hash<decltype(activeTouch.touch.identifier)>()(activeTouch.touch.identifier);
@@ -71,7 +76,7 @@ bool operator()(const ActiveTouch &lhs, const ActiveTouch &rhs) const {
7176
};
7277

7378
static void UpdateActiveTouchWithUITouch(ActiveTouch &activeTouch, UITouch *uiTouch, UIView *rootComponentView) {
74-
CGPoint offsetPoint = [uiTouch locationInView:uiTouch.view];
79+
CGPoint offsetPoint = [uiTouch locationInView:activeTouch.componentView];
7580
CGPoint screenPoint = [uiTouch locationInView:uiTouch.window];
7681
CGPoint pagePoint = [uiTouch locationInView:rootComponentView];
7782

@@ -97,6 +102,8 @@ static ActiveTouch CreateTouchWithUITouch(UITouch *uiTouch, UIView *rootComponen
97102
activeTouch.touch.target = (Tag)componentView.tag;
98103
}
99104

105+
activeTouch.componentView = componentView;
106+
100107
UpdateActiveTouchWithUITouch(activeTouch, uiTouch, rootComponentView);
101108
return activeTouch;
102109
}

0 commit comments

Comments
 (0)