diff --git a/lib/ios/RNNComponentPresenter.m b/lib/ios/RNNComponentPresenter.m index 1a0b9a8ced2..5d75613ae95 100644 --- a/lib/ios/RNNComponentPresenter.m +++ b/lib/ios/RNNComponentPresenter.m @@ -165,7 +165,8 @@ - (void)removeTitleComponentIfNeeded:(RNNNavigationOptions *)options { } - (void)renderComponents:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock { - [self setCustomNavigationTitleView:options perform:readyBlock]; + RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]]; + [self setCustomNavigationTitleView:withDefault perform:readyBlock]; } - (void)setCustomNavigationTitleView:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock { diff --git a/lib/ios/RNNComponentViewController.m b/lib/ios/RNNComponentViewController.m index 5d98fd81652..40c6e5d5b5e 100644 --- a/lib/ios/RNNComponentViewController.m +++ b/lib/ios/RNNComponentViewController.m @@ -28,6 +28,7 @@ - (void)bindViewController:(UIViewController *)viewController { } - (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions { + _defaultOptions = defaultOptions; [_presenter setDefaultOptions:defaultOptions]; } diff --git a/lib/ios/RNNStackPresenter.m b/lib/ios/RNNStackPresenter.m index 4bf3203c7aa..d3e595de69c 100644 --- a/lib/ios/RNNStackPresenter.m +++ b/lib/ios/RNNStackPresenter.m @@ -198,14 +198,15 @@ - (void)setCustomNavigationBarView:(RNNNavigationOptions *)options perform:(RNNR } - (void)setCustomNavigationComponentBackground:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock { + RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]]; RNNStackController* stack = self.boundViewController; - if (![options.topBar.background.component.waitForRender getWithDefaultValue:NO] && readyBlock) { + if (![withDefault.topBar.background.component.waitForRender getWithDefaultValue:NO] && readyBlock) { readyBlock(); readyBlock = nil; } - if (options.topBar.background.component.name.hasValue) { + if (withDefault.topBar.background.component.name.hasValue) { NSString* currentChildComponentId = [stack getCurrentChild].layoutInfo.componentId; - RNNReactView *reactView = [_componentRegistry createComponentIfNotExists:options.topBar.background.component parentComponentId:currentChildComponentId reactViewReadyBlock:readyBlock]; + RNNReactView *reactView = [_componentRegistry createComponentIfNotExists:withDefault.topBar.background.component parentComponentId:currentChildComponentId reactViewReadyBlock:readyBlock]; _customTopBarBackgroundReactView = reactView; } else { diff --git a/playground/ios/NavigationTests/RNNComponentPresenterTest.m b/playground/ios/NavigationTests/RNNComponentPresenterTest.m index 9cb4db0e50b..ec49043e941 100644 --- a/playground/ios/NavigationTests/RNNComponentPresenterTest.m +++ b/playground/ios/NavigationTests/RNNComponentPresenterTest.m @@ -161,11 +161,34 @@ - (void)testRenderComponentsCreateReactViewWithBoundComponentId { RNNComponentViewController* boundViewController = [RNNComponentViewController new]; RNNLayoutInfo* layoutInfo = [self createLayoutInfoWithComponentId:@"componentId"]; boundViewController.layoutInfo = layoutInfo; + boundViewController.defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; [self.uut boundViewController:boundViewController]; - self.options.topBar.title.component = [[RNNComponentOptions alloc] initWithDict:@{@"name": @"titleComponent"}]; + self.options.topBar.title.component = [[RNNComponentOptions alloc] initWithDict:@{@"name": @"titleComponent", @"componentId": @"id"}]; - [[(id)self.componentRegistry expect] createComponentIfNotExists:self.options.topBar.title.component parentComponentId:self.uut.boundComponentId reactViewReadyBlock:[OCMArg any]]; + [[(id)self.componentRegistry expect] createComponentIfNotExists:[OCMArg checkWithBlock:^BOOL(RNNComponentOptions* options) { + return [options.name.get isEqual:@"titleComponent"] && + [options.componentId.get isEqual:@"id"]; + }] parentComponentId:self.uut.boundComponentId reactViewReadyBlock:[OCMArg any]]; + [self.uut renderComponents:self.options perform:nil]; + [(id)self.componentRegistry verify]; + + + XCTAssertEqual(self.uut.boundComponentId, @"componentId"); +} + +- (void)testRenderComponentsCreateReactViewFromDefaultOptions { + RNNComponentViewController* boundViewController = [RNNComponentViewController new]; + boundViewController.layoutInfo = [self createLayoutInfoWithComponentId:@"componentId"]; + self.uut.defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + [self.uut boundViewController:boundViewController]; + + self.uut.defaultOptions.topBar.title.component = [[RNNComponentOptions alloc] initWithDict:@{@"name": @"titleComponent", @"componentId": @"id"}]; + + [[(id)self.componentRegistry expect] createComponentIfNotExists:[OCMArg checkWithBlock:^BOOL(RNNComponentOptions* options) { + return [options.name.get isEqual:@"titleComponent"] && + [options.componentId.get isEqual:@"id"]; + }] parentComponentId:self.uut.boundComponentId reactViewReadyBlock:[OCMArg any]]; [self.uut renderComponents:self.options perform:nil]; [(id)self.componentRegistry verify];