From fe8cd5cf3e68398cd095b5c5b38c1547a6770773 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Thu, 15 Oct 2020 10:44:29 -0700 Subject: [PATCH] Fabric: Lazy initialization of RCTSurfaceTouchHandler on the main thread Summary: RCTSurfaceTouchHandler is not a thread-safe object and must be used (and initialized) on the main thread. Therefore we need to move the initialization to `view` method which is guaranteed to be called on the main thread. Changelog: [Internal] Fabric-specific internal change. Reviewed By: sammy-SC Differential Revision: D24290776 fbshipit-source-id: fc1f2f157599aff6fca053451f89bf7cca3c812a --- React/Fabric/Surface/RCTFabricSurface.mm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/React/Fabric/Surface/RCTFabricSurface.mm b/React/Fabric/Surface/RCTFabricSurface.mm index 9d73a3d3caa..35368dada39 100644 --- a/React/Fabric/Surface/RCTFabricSurface.mm +++ b/React/Fabric/Surface/RCTFabricSurface.mm @@ -58,8 +58,6 @@ using namespace facebook::react; _maximumSize = CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX); - _touchHandler = [RCTSurfaceTouchHandler new]; - _stage = RCTSurfaceStageSurfaceDidInitialize; } @@ -106,6 +104,7 @@ using namespace facebook::react; if (!_view) { _view = [[RCTSurfaceView alloc] initWithSurface:(RCTSurface *)self]; + _touchHandler = [RCTSurfaceTouchHandler new]; [_touchHandler attachToView:_view]; }