Skip to content

Commit

Permalink
Fix bottomTab merging options with default (#5885)
Browse files Browse the repository at this point in the history
When updating bottomTab options with mergeOptions - default options were not taken into account and therefore were not applied to the newly created tabBarItem
  • Loading branch information
yogevbd authored Jan 29, 2020
1 parent 4bfa7c5 commit 513138e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
2 changes: 2 additions & 0 deletions lib/ios/Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

@interface Color : Param

+ (instancetype)withColor:(UIColor *)value;

- (instancetype)initWithValue:(UIColor *)value;

- (UIColor *)get;
Expand Down
4 changes: 4 additions & 0 deletions lib/ios/Color.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ @interface Color()

@implementation Color

+ (instancetype)withColor:(UIColor *)value {
return [[Color alloc] initWithValue:value];
}

- (instancetype)initWithValue:(UIColor *)value {
return [super initWithValue:value];
}
Expand Down
27 changes: 11 additions & 16 deletions lib/ios/RNNBasePresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ - (void)applyOptions:(RNNNavigationOptions *)options {
}

- (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)resolvedOptions {
UIViewController *viewController = self.boundViewController;
if (options.bottomTab.badge.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
UIViewController* viewController = self.boundViewController;
RNNNavigationOptions* withDefault = (RNNNavigationOptions *) [[resolvedOptions withDefault:_defaultOptions] overrideOptions:options];

if (options.bottomTab.badge.hasValue) {
[viewController setTabBarItemBadge:options.bottomTab.badge.get];
}

Expand All @@ -130,44 +132,37 @@ - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigat
}

if (options.bottomTab.text.hasValue) {
RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [resolvedOptions overrideOptions:options];
UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
viewController.tabBarItem = tabItem;
}

if (options.bottomTab.icon.hasValue) {
RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [resolvedOptions overrideOptions:options];
UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
viewController.tabBarItem = tabItem;
}

if (options.bottomTab.selectedIcon.hasValue) {
RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [resolvedOptions overrideOptions:options];
UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
viewController.tabBarItem = tabItem;
}

if (options.bottomTab.textColor.hasValue) {
RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [resolvedOptions overrideOptions:options];
UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
viewController.tabBarItem = tabItem;
}

if (options.bottomTab.selectedTextColor.hasValue) {
RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [resolvedOptions overrideOptions:options];
UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
viewController.tabBarItem = tabItem;
}

if (options.bottomTab.iconColor.hasValue) {
RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [resolvedOptions overrideOptions:options];
UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
viewController.tabBarItem = tabItem;
}

if (options.bottomTab.selectedIconColor.hasValue) {
RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [resolvedOptions overrideOptions:options];
UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
viewController.tabBarItem = tabItem;
}
}
Expand Down
13 changes: 12 additions & 1 deletion playground/ios/NavigationTests/RNNBasePresenterTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ - (void)testApplyOptionsOnInit_setSwipeToDismiss {
XCTAssertTrue(_boundViewController.modalInPresentation);
}


- (void)testMergeOptions_shouldSetTabBarItemColorWithDefaultOptions {
RNNNavigationOptions* defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
defaultOptions.bottomTab.selectedIconColor = [Color withColor:UIColor.greenColor];
self.uut.defaultOptions = defaultOptions;

RNNNavigationOptions* mergeOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
mergeOptions.bottomTab.text = [[Text alloc] initWithValue:@"title"];
OCMStub([self.mockBoundViewController parentViewController]).andReturn([UITabBarController new]);

[self.uut mergeOptions:mergeOptions resolvedOptions:self.options];
XCTAssertEqual(self.uut.boundViewController.tabBarItem.title, @"title");
}

@end

0 comments on commit 513138e

Please sign in to comment.