Skip to content

Commit

Permalink
(Easy) 1/n In RCTSurfaceHostingComponent, access ckComponent from mai…
Browse files Browse the repository at this point in the history
…n 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
  • Loading branch information
p-sun authored and facebook-github-bot committed Mar 29, 2022
1 parent eeb244a commit 1874c81
Showing 1 changed file with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1874c81

Please sign in to comment.