From 43501329328a76f0e26efc65a1a90cbdc01d0fb4 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Sat, 30 Nov 2019 12:29:34 -0800 Subject: [PATCH] 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 --- React/Fabric/RCTSurfaceTouchHandler.mm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/React/Fabric/RCTSurfaceTouchHandler.mm b/React/Fabric/RCTSurfaceTouchHandler.mm index 147dea34fab..ffe0a62363e 100644 --- a/React/Fabric/RCTSurfaceTouchHandler.mm +++ b/React/Fabric/RCTSurfaceTouchHandler.mm @@ -57,6 +57,11 @@ struct ActiveTouch { Touch touch; SharedTouchEventEmitter eventEmitter; + /* + * A component view on which the touch was begun. + */ + __strong UIView *componentView = nil; + struct Hasher { size_t operator()(const ActiveTouch &activeTouch) const { return std::hash()(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; }