Skip to content

Commit

Permalink
Fix topBar component setDefaultOptions issue (#5710)
Browse files Browse the repository at this point in the history
* Closes #5622

* Fix unit tests
  • Loading branch information
yogevbd authored Dec 2, 2019
1 parent 4fbf1cf commit 4a1b8b4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/ios/RNNComponentPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions lib/ios/RNNComponentViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ - (void)bindViewController:(UIViewController *)viewController {
}

- (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions {
_defaultOptions = defaultOptions;
[_presenter setDefaultOptions:defaultOptions];
}

Expand Down
7 changes: 4 additions & 3 deletions lib/ios/RNNStackPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
27 changes: 25 additions & 2 deletions playground/ios/NavigationTests/RNNComponentPresenterTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down

0 comments on commit 4a1b8b4

Please sign in to comment.