From 1874c81003b468554c227541fec5e29c4adfb82f Mon Sep 17 00:00:00 2001 From: Paige Sun Date: Tue, 29 Mar 2022 11:52:49 -0700 Subject: [PATCH] (Easy) 1/n In RCTSurfaceHostingComponent, access ckComponent from main queue to pass assertion Summary: Changelog: Before diff, we always hit assert the `'self.component' must be called on the main thread` assertion whenever we open a surface with a RCTSurfaceHostingComponent (React Native surface inside a CKComponent). Reviewed By: RSNara Differential Revision: D35152263 fbshipit-source-id: 1b06ca9d2ae7ca211120b71504e2eeaabaaf3bfd --- .../RCTSurfaceHostingComponentController.mm | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/Libraries/SurfaceHostingComponent/RCTSurfaceHostingComponentController.mm b/Libraries/SurfaceHostingComponent/RCTSurfaceHostingComponentController.mm index 4bbaa89bea9ab9..24d83b48d229f7 100644 --- a/Libraries/SurfaceHostingComponent/RCTSurfaceHostingComponentController.mm +++ b/Libraries/SurfaceHostingComponent/RCTSurfaceHostingComponentController.mm @@ -77,18 +77,34 @@ - (void)updateSurfaceWithComponent:(RCTSurfaceHostingComponent *)component - (void)setIntrinsicSize:(CGSize)intrinsicSize { - [self.component updateState:^(RCTSurfaceHostingComponentState *state) { - return [RCTSurfaceHostingComponentState newWithStage:state.stage - intrinsicSize:intrinsicSize]; - } mode:[self suitableStateUpdateMode]]; + __weak __typeof(self) weakSelf = self; + dispatch_async(dispatch_get_main_queue(), ^{ + __strong __typeof(self) strongSelf = weakSelf; + if (!strongSelf) { + return; + } + + [strongSelf.component updateState:^(RCTSurfaceHostingComponentState *state) { + return [RCTSurfaceHostingComponentState newWithStage:state.stage + intrinsicSize:intrinsicSize]; + } mode:[strongSelf suitableStateUpdateMode]]; + }); } - (void)setStage:(RCTSurfaceStage)stage { - [self.component updateState:^(RCTSurfaceHostingComponentState *state) { - return [RCTSurfaceHostingComponentState newWithStage:stage - intrinsicSize:state.intrinsicSize]; - } mode:[self suitableStateUpdateMode]]; + __weak __typeof(self) weakSelf = self; + dispatch_async(dispatch_get_main_queue(), ^{ + __strong __typeof(self) strongSelf = weakSelf; + if (!strongSelf) { + return; + } + + [strongSelf.component updateState:^(RCTSurfaceHostingComponentState *state) { + return [RCTSurfaceHostingComponentState newWithStage:stage + intrinsicSize:state.intrinsicSize]; + } mode:[strongSelf suitableStateUpdateMode]]; + }); } - (CKUpdateMode)suitableStateUpdateMode