diff --git a/ios/RNNStackPresenter.mm b/ios/RNNStackPresenter.mm index 7b98c050f6..72464711a0 100644 --- a/ios/RNNStackPresenter.mm +++ b/ios/RNNStackPresenter.mm @@ -167,24 +167,14 @@ - (void)mergeOptions:(RNNNavigationOptions *)mergeOptions - (void)renderComponents:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock { - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ - dispatch_group_t group = dispatch_group_create(); - - dispatch_group_enter(group); - dispatch_async(dispatch_get_main_queue(), ^{ - [self setCustomNavigationComponentBackground:options - perform:^{ - dispatch_group_leave(group); - }]; - }); - - dispatch_group_wait(group, DISPATCH_TIME_FOREVER); - - dispatch_async(dispatch_get_main_queue(), ^{ - if (readyBlock) { - readyBlock(); - } - }); + dispatch_async(dispatch_get_main_queue(), ^{ + [self setCustomNavigationComponentBackground:options + perform:^{ + if (readyBlock) { + dispatch_async(dispatch_get_main_queue(), + readyBlock); + } + }]; }); } diff --git a/playground/ios/NavigationTests/RNNStackPresenterTest.mm b/playground/ios/NavigationTests/RNNStackPresenterTest.mm index 927a406534..49ef0d83ae 100644 --- a/playground/ios/NavigationTests/RNNStackPresenterTest.mm +++ b/playground/ios/NavigationTests/RNNStackPresenterTest.mm @@ -6,6 +6,13 @@ #import #import +@interface RNNStackPresenter (Testing) + +- (void)setCustomNavigationComponentBackground:(RNNNavigationOptions *)options + perform:(RNNReactViewReadyCompletionBlock)readyBlock; + +@end + @interface RNNStackPresenterTest : XCTestCase @property(nonatomic, strong) RNNStackPresenter *uut; @@ -123,4 +130,19 @@ - (void)testBackgroundColor_validColor { XCTAssertTrue([self.boundViewController.view.backgroundColor isEqual:expectedColor]); } +- (void)testRenderComponentsCompletesOnMainThread { + id presenter = [OCMockObject partialMockForObject:self.uut]; + OCMStub([presenter setCustomNavigationComponentBackground:OCMArg.any + perform:OCMArg.invokeBlock]); + XCTestExpectation *completion = [self expectationWithDescription:@"render completion"]; + + [presenter renderComponents:self.options + perform:^{ + XCTAssertTrue(NSThread.isMainThread); + [completion fulfill]; + }]; + + [self waitForExpectations:@[ completion ] timeout:1]; +} + @end