mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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
This commit is contained in:
1 parent
7ce8babfef
commit
4350132932
1 file changed
+8
-1
@@ -57,6 +57,11 @@ struct ActiveTouch {
|
||||
Touch touch;
|
||||
SharedTouchEventEmitter eventEmitter;
|
||||
|
||||
/*
|
||||
* A component view on which the touch was begun.
|
||||
*/
|
||||
__strong UIView<RCTComponentViewProtocol> *componentView = nil;
|
||||
|
||||
struct Hasher {
|
||||
size_t operator()(const ActiveTouch &activeTouch) const {
|
||||
return std::hash<decltype(activeTouch.touch.identifier)>()(activeTouch.touch.identifier);
|
||||
@@ -71,7 +76,7 @@ struct ActiveTouch {
|
||||
};
|
||||
|
||||
static void UpdateActiveTouchWithUITouch(ActiveTouch &activeTouch, UITouch *uiTouch, UIView *rootComponentView) {
|
||||
CGPoint offsetPoint = [uiTouch locationInView:uiTouch.view];
|
||||
CGPoint offsetPoint = [uiTouch locationInView:activeTouch.componentView];
|
||||
CGPoint screenPoint = [uiTouch locationInView:uiTouch.window];
|
||||
CGPoint pagePoint = [uiTouch locationInView:rootComponentView];
|
||||
|
||||
@@ -97,6 +102,8 @@ static ActiveTouch CreateTouchWithUITouch(UITouch *uiTouch, UIView *rootComponen
|
||||
activeTouch.touch.target = (Tag)componentView.tag;
|
||||
}
|
||||
|
||||
activeTouch.componentView = componentView;
|
||||
|
||||
UpdateActiveTouchWithUITouch(activeTouch, uiTouch, rootComponentView);
|
||||
return activeTouch;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user