Skip to content

Commit 1874c81

Browse files
p-sunfacebook-github-bot
authored andcommitted
(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
1 parent eeb244a commit 1874c81

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

Libraries/SurfaceHostingComponent/RCTSurfaceHostingComponentController.mm

+24-8
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,34 @@ - (void)updateSurfaceWithComponent:(RCTSurfaceHostingComponent *)component
7777

7878
- (void)setIntrinsicSize:(CGSize)intrinsicSize
7979
{
80-
[self.component updateState:^(RCTSurfaceHostingComponentState *state) {
81-
return [RCTSurfaceHostingComponentState newWithStage:state.stage
82-
intrinsicSize:intrinsicSize];
83-
} mode:[self suitableStateUpdateMode]];
80+
__weak __typeof(self) weakSelf = self;
81+
dispatch_async(dispatch_get_main_queue(), ^{
82+
__strong __typeof(self) strongSelf = weakSelf;
83+
if (!strongSelf) {
84+
return;
85+
}
86+
87+
[strongSelf.component updateState:^(RCTSurfaceHostingComponentState *state) {
88+
return [RCTSurfaceHostingComponentState newWithStage:state.stage
89+
intrinsicSize:intrinsicSize];
90+
} mode:[strongSelf suitableStateUpdateMode]];
91+
});
8492
}
8593

8694
- (void)setStage:(RCTSurfaceStage)stage
8795
{
88-
[self.component updateState:^(RCTSurfaceHostingComponentState *state) {
89-
return [RCTSurfaceHostingComponentState newWithStage:stage
90-
intrinsicSize:state.intrinsicSize];
91-
} mode:[self suitableStateUpdateMode]];
96+
__weak __typeof(self) weakSelf = self;
97+
dispatch_async(dispatch_get_main_queue(), ^{
98+
__strong __typeof(self) strongSelf = weakSelf;
99+
if (!strongSelf) {
100+
return;
101+
}
102+
103+
[strongSelf.component updateState:^(RCTSurfaceHostingComponentState *state) {
104+
return [RCTSurfaceHostingComponentState newWithStage:stage
105+
intrinsicSize:state.intrinsicSize];
106+
} mode:[strongSelf suitableStateUpdateMode]];
107+
});
92108
}
93109

94110
- (CKUpdateMode)suitableStateUpdateMode

0 commit comments

Comments
 (0)