Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions ios/RNNStackPresenter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}];
});
}

Expand Down
22 changes: 22 additions & 0 deletions playground/ios/NavigationTests/RNNStackPresenterTest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
#import <ReactNativeNavigation/RNNStackPresenter.h>
#import <XCTest/XCTest.h>

@interface RNNStackPresenter (Testing)

- (void)setCustomNavigationComponentBackground:(RNNNavigationOptions *)options
perform:(RNNReactViewReadyCompletionBlock)readyBlock;

@end

@interface RNNStackPresenterTest : XCTestCase

@property(nonatomic, strong) RNNStackPresenter *uut;
Expand Down Expand Up @@ -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