diff --git a/lib/ios/BottomTabAppearancePresenter.h b/lib/ios/BottomTabAppearancePresenter.h index 4c0ed688255..928fdc2bee0 100644 --- a/lib/ios/BottomTabAppearancePresenter.h +++ b/lib/ios/BottomTabAppearancePresenter.h @@ -3,6 +3,4 @@ API_AVAILABLE(ios(13.0)) @interface BottomTabAppearancePresenter : BottomTabPresenter -- (instancetype)initWithDefaultOptions:(RNNNavigationOptions *)defaultOptions children:(NSArray *)children; - @end diff --git a/lib/ios/BottomTabAppearancePresenter.m b/lib/ios/BottomTabAppearancePresenter.m index 26d01616613..9eae442379e 100644 --- a/lib/ios/BottomTabAppearancePresenter.m +++ b/lib/ios/BottomTabAppearancePresenter.m @@ -3,16 +3,8 @@ @implementation BottomTabAppearancePresenter -- (instancetype)initWithDefaultOptions:(RNNNavigationOptions *)defaultOptions children:(NSArray *)children { - self = [super initWithDefaultOptions:defaultOptions]; - for (UIViewController* child in children) { - child.tabBarItem.standardAppearance = [[UITabBarAppearance alloc] init]; - } - return self; -} - - (void)createTabBarItem:(UIViewController *)child bottomTabOptions:(RNNBottomTabOptions *)bottomTabOptions { - child.tabBarItem = [TabBarItemAppearanceCreator updateTabBarItem:child.tabBarItem bottomTabOptions:bottomTabOptions]; + child.tabBarItem = [TabBarItemAppearanceCreator createTabBarItem:bottomTabOptions mergeItem:child.tabBarItem]; } @end diff --git a/lib/ios/BottomTabPresenter.m b/lib/ios/BottomTabPresenter.m index de5cc4b9aea..bf76cc77ea1 100644 --- a/lib/ios/BottomTabPresenter.m +++ b/lib/ios/BottomTabPresenter.m @@ -15,21 +15,21 @@ - (void)applyOptions:(RNNNavigationOptions *)options child:(UIViewController *)c - (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options child:(UIViewController *)child { RNNNavigationOptions * withDefault = [options withDefault:self.defaultOptions]; + [self createTabBarItem:child bottomTabOptions:withDefault.bottomTab]; [child setTabBarItemBadge:[withDefault.bottomTab.badge getWithDefaultValue:[NSNull null]]]; [child setTabBarItemBadgeColor:[withDefault.bottomTab.badgeColor getWithDefaultValue:nil]]; - [self createTabBarItem:child bottomTabOptions:withDefault.bottomTab]; } - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)resolvedOptions child:(UIViewController *)child { RNNNavigationOptions* withDefault = (RNNNavigationOptions *) [[resolvedOptions withDefault:self.defaultOptions] overrideOptions:options]; + if (options.bottomTab.hasValue) [self createTabBarItem:child bottomTabOptions:withDefault.bottomTab]; if (options.bottomTab.badge.hasValue) [child setTabBarItemBadge:options.bottomTab.badge.get]; if (options.bottomTab.badgeColor.hasValue) [child setTabBarItemBadgeColor:options.bottomTab.badgeColor.get]; - if (options.bottomTab.hasValue) [self createTabBarItem:child bottomTabOptions:withDefault.bottomTab]; } - (void)createTabBarItem:(UIViewController *)child bottomTabOptions:(RNNBottomTabOptions *)bottomTabOptions { - child.tabBarItem = [RNNTabBarItemCreator updateTabBarItem:child.tabBarItem bottomTabOptions:bottomTabOptions]; + child.tabBarItem = [RNNTabBarItemCreator createTabBarItem:bottomTabOptions mergeItem:child.tabBarItem]; } @end diff --git a/lib/ios/BottomTabPresenterCreator.h b/lib/ios/BottomTabPresenterCreator.h index 2251cf771b1..6291d319200 100644 --- a/lib/ios/BottomTabPresenterCreator.h +++ b/lib/ios/BottomTabPresenterCreator.h @@ -3,6 +3,6 @@ @interface BottomTabPresenterCreator : NSObject -+ (BottomTabPresenter *)createWithDefaultOptions:(RNNNavigationOptions *)defaultOptions children:(NSArray *)children; ++ (BottomTabPresenter *)createWithDefaultOptions:(RNNNavigationOptions *)defaultOptions; @end diff --git a/lib/ios/BottomTabPresenterCreator.m b/lib/ios/BottomTabPresenterCreator.m index ccd24082c08..7c29aacf067 100644 --- a/lib/ios/BottomTabPresenterCreator.m +++ b/lib/ios/BottomTabPresenterCreator.m @@ -3,9 +3,9 @@ @implementation BottomTabPresenterCreator -+ (BottomTabPresenter *)createWithDefaultOptions:(RNNNavigationOptions *)defaultOptions children:(NSArray *)children { ++ (BottomTabPresenter *)createWithDefaultOptions:(RNNNavigationOptions *)defaultOptions { if (@available(iOS 13.0, *)) { - return [[BottomTabAppearancePresenter alloc] initWithDefaultOptions:defaultOptions children:children]; + return [[BottomTabAppearancePresenter alloc] initWithDefaultOptions:defaultOptions]; } else { return [[BottomTabPresenter alloc] initWithDefaultOptions:defaultOptions]; } diff --git a/lib/ios/RNNControllerFactory.m b/lib/ios/RNNControllerFactory.m index b9d2b10fbd3..5db4804781f 100644 --- a/lib/ios/RNNControllerFactory.m +++ b/lib/ios/RNNControllerFactory.m @@ -152,7 +152,7 @@ - (UIViewController *)createBottomTabs:(RNNLayoutNode*)node { RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:node.data[@"options"]]; RNNBottomTabsPresenter* presenter = [BottomTabsPresenterCreator createWithDefaultOptions:_defaultOptions]; NSArray *childViewControllers = [self extractChildrenViewControllersFromNode:node]; - BottomTabPresenter* bottomTabPresenter = [BottomTabPresenterCreator createWithDefaultOptions:_defaultOptions children:childViewControllers];; + BottomTabPresenter* bottomTabPresenter = [BottomTabPresenterCreator createWithDefaultOptions:_defaultOptions]; RNNDotIndicatorPresenter* dotIndicatorPresenter = [[RNNDotIndicatorPresenter alloc] initWithDefaultOptions:_defaultOptions]; BottomTabsBaseAttacher* bottomTabsAttacher = [_bottomTabsAttachModeFactory fromOptions:options]; diff --git a/lib/ios/RNNTabBarItemCreator.h b/lib/ios/RNNTabBarItemCreator.h index b9a9eddb480..7d419296bca 100644 --- a/lib/ios/RNNTabBarItemCreator.h +++ b/lib/ios/RNNTabBarItemCreator.h @@ -4,7 +4,9 @@ @interface RNNTabBarItemCreator : NSObject -+ (UITabBarItem *)updateTabBarItem:(UITabBarItem *)tabItem bottomTabOptions:(RNNBottomTabOptions *)bottomTabOptions; ++ (UITabBarItem *)createTabBarItem:(RNNBottomTabOptions *)bottomTabOptions mergeItem:(UITabBarItem *)mergeItem; + ++ (UITabBarItem *)createTabBarItem:(UITabBarItem *)mergeItem; + (void)setTitleAttributes:(UITabBarItem *)tabItem titleAttributes:(NSDictionary *)titleAttributes; diff --git a/lib/ios/RNNTabBarItemCreator.m b/lib/ios/RNNTabBarItemCreator.m index d3f7fff1b7d..90aa4e4b4da 100644 --- a/lib/ios/RNNTabBarItemCreator.m +++ b/lib/ios/RNNTabBarItemCreator.m @@ -4,7 +4,12 @@ @implementation RNNTabBarItemCreator -+ (UITabBarItem *)updateTabBarItem:(UITabBarItem *)tabItem bottomTabOptions:(RNNBottomTabOptions *)bottomTabOptions { ++ (UITabBarItem *)createTabBarItem:(UITabBarItem *)mergeItem { + return [UITabBarItem new]; +} + ++ (UITabBarItem *)createTabBarItem:(RNNBottomTabOptions *)bottomTabOptions mergeItem:(UITabBarItem *)mergeItem { + UITabBarItem* tabItem = [self createTabBarItem:mergeItem]; UIImage* icon = [bottomTabOptions.icon getWithDefaultValue:nil]; UIImage* selectedIcon = [bottomTabOptions.selectedIcon getWithDefaultValue:icon]; UIColor* iconColor = [bottomTabOptions.iconColor getWithDefaultValue:nil]; diff --git a/lib/ios/TabBarItemAppearanceCreator.h b/lib/ios/TabBarItemAppearanceCreator.h index 8efd8493a39..be6776193ea 100644 --- a/lib/ios/TabBarItemAppearanceCreator.h +++ b/lib/ios/TabBarItemAppearanceCreator.h @@ -1,5 +1,6 @@ #import "RNNTabBarItemCreator.h" +API_AVAILABLE(ios(13.0)) @interface TabBarItemAppearanceCreator : RNNTabBarItemCreator @end diff --git a/lib/ios/TabBarItemAppearanceCreator.m b/lib/ios/TabBarItemAppearanceCreator.m index 3a90b42797d..6198d65a83e 100644 --- a/lib/ios/TabBarItemAppearanceCreator.m +++ b/lib/ios/TabBarItemAppearanceCreator.m @@ -2,6 +2,12 @@ @implementation TabBarItemAppearanceCreator ++ (UITabBarItem *)createTabBarItem:(UITabBarItem *)mergeItem { + UITabBarItem* tabBarItem = [super createTabBarItem:mergeItem]; + tabBarItem.standardAppearance = mergeItem.standardAppearance ?: [[UITabBarAppearance alloc] init]; + return tabBarItem; +} + + (void)setTitleAttributes:(UITabBarItem *)tabItem titleAttributes:(NSDictionary *)titleAttributes { tabItem.standardAppearance.stackedLayoutAppearance.normal.titleTextAttributes = titleAttributes; } diff --git a/playground/ios/NavigationTests/BottomTabPresenterTest.m b/playground/ios/NavigationTests/BottomTabPresenterTest.m index b8b8ed24622..7224ad3baeb 100644 --- a/playground/ios/NavigationTests/BottomTabPresenterTest.m +++ b/playground/ios/NavigationTests/BottomTabPresenterTest.m @@ -52,4 +52,18 @@ - (void)testMergeOptions_shouldSetTabBarItemColorWithDefaultOptions { XCTAssertEqual(self.componentViewController.tabBarItem.title, @"title"); } +- (void)testMergeOptions_shouldCreateNewTabBarItemInstance { + 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"]; + + UITabBarItem* currentTabBarItem = self.componentViewController.tabBarItem; + [self.uut mergeOptions:mergeOptions resolvedOptions:self.options child:self.componentViewController]; + UITabBarItem* newTabBarItem = self.componentViewController.tabBarItem; + XCTAssertNotEqual(currentTabBarItem, newTabBarItem); +} + @end diff --git a/playground/ios/NavigationTests/RNNBottomTabsAppearancePresenterTest.m b/playground/ios/NavigationTests/RNNBottomTabsAppearancePresenterTest.m index ed021b6385b..304a6d6e006 100644 --- a/playground/ios/NavigationTests/RNNBottomTabsAppearancePresenterTest.m +++ b/playground/ios/NavigationTests/RNNBottomTabsAppearancePresenterTest.m @@ -25,7 +25,7 @@ - (void)setUp { self.children = @[[[RNNComponentViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[[RNNComponentPresenter alloc] initWithDefaultOptions:nil] options:nil defaultOptions:nil]]; self.dotIndicatorPresenter = [OCMockObject partialMockForObject:[[RNNDotIndicatorPresenter alloc] initWithDefaultOptions:nil]]; self.uut = [OCMockObject partialMockForObject:[BottomTabsPresenterCreator createWithDefaultOptions:nil]]; - self.boundViewController = [OCMockObject partialMockForObject:[[RNNBottomTabsController alloc] initWithLayoutInfo:nil creator:nil options:nil defaultOptions:nil presenter:self.uut bottomTabPresenter:[BottomTabPresenterCreator createWithDefaultOptions:nil children:self.children] dotIndicatorPresenter:self.dotIndicatorPresenter eventEmitter:nil childViewControllers:self.children bottomTabsAttacher:nil]]; + self.boundViewController = [OCMockObject partialMockForObject:[[RNNBottomTabsController alloc] initWithLayoutInfo:nil creator:nil options:nil defaultOptions:nil presenter:self.uut bottomTabPresenter:[BottomTabPresenterCreator createWithDefaultOptions:nil] dotIndicatorPresenter:self.dotIndicatorPresenter eventEmitter:nil childViewControllers:self.children bottomTabsAttacher:nil]]; [self.uut bindViewController:self.boundViewController]; self.options = [[RNNNavigationOptions alloc] initEmptyOptions]; } diff --git a/playground/ios/NavigationTests/RNNBottomTabsController+Helpers.m b/playground/ios/NavigationTests/RNNBottomTabsController+Helpers.m index 605f251d68a..58c099beffc 100644 --- a/playground/ios/NavigationTests/RNNBottomTabsController+Helpers.m +++ b/playground/ios/NavigationTests/RNNBottomTabsController+Helpers.m @@ -11,7 +11,7 @@ + (RNNBottomTabsController *)create { + (RNNBottomTabsController *)createWithChildren:(NSArray *)children { RNNNavigationOptions* defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; - return [[RNNBottomTabsController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:defaultOptions presenter:[BottomTabsPresenterCreator createWithDefaultOptions:defaultOptions] bottomTabPresenter:[BottomTabPresenterCreator createWithDefaultOptions:defaultOptions children:children] dotIndicatorPresenter:[[RNNDotIndicatorPresenter alloc] initWithDefaultOptions:defaultOptions] eventEmitter:nil childViewControllers:children bottomTabsAttacher:nil]; + return [[RNNBottomTabsController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:defaultOptions presenter:[BottomTabsPresenterCreator createWithDefaultOptions:defaultOptions] bottomTabPresenter:[BottomTabPresenterCreator createWithDefaultOptions:defaultOptions] dotIndicatorPresenter:[[RNNDotIndicatorPresenter alloc] initWithDefaultOptions:defaultOptions] eventEmitter:nil childViewControllers:children bottomTabsAttacher:nil]; } @end diff --git a/playground/ios/NavigationTests/RNNDotIndicatorPresenterTest.m b/playground/ios/NavigationTests/RNNDotIndicatorPresenterTest.m index 66e22a0e2f1..6a91edef25d 100644 --- a/playground/ios/NavigationTests/RNNDotIndicatorPresenterTest.m +++ b/playground/ios/NavigationTests/RNNDotIndicatorPresenterTest.m @@ -20,7 +20,7 @@ @implementation RNNDotIndicatorPresenterTest - (void)setUp { [super setUp]; self.child = [self createChild]; - self.bottomTabPresenter = [BottomTabPresenterCreator createWithDefaultOptions:nil children:@[self.child]]; + self.bottomTabPresenter = [BottomTabPresenterCreator createWithDefaultOptions:nil]; self.uut = [OCMockObject partialMockForObject:[RNNDotIndicatorPresenter new]]; self.bottomTabs = [OCMockObject partialMockForObject:[RNNBottomTabsController createWithChildren:@[self.child]]]; diff --git a/playground/ios/NavigationTests/RNNRootViewControllerTest.m b/playground/ios/NavigationTests/RNNRootViewControllerTest.m index 7ea03d986bc..00ac960904e 100644 --- a/playground/ios/NavigationTests/RNNRootViewControllerTest.m +++ b/playground/ios/NavigationTests/RNNRootViewControllerTest.m @@ -180,8 +180,6 @@ - (void)testTabBadge { NSString* tabBadgeInput = @"5"; self.options.bottomTab.badge = [[Text alloc] initWithValue:tabBadgeInput]; NSMutableArray* controllers = [NSMutableArray new]; - UITabBarItem* item = [[UITabBarItem alloc] initWithTitle:@"A Tab" image:nil tag:1]; - [self.uut setTabBarItem:item]; [controllers addObject:self.uut]; __unused RNNBottomTabsController* vc = [RNNBottomTabsController createWithChildren:controllers]; [self.uut willMoveToParentViewController:vc]; diff --git a/playground/ios/NavigationTests/RNNTabBarControllerTest.m b/playground/ios/NavigationTests/RNNTabBarControllerTest.m index c1fbd869203..821431d364b 100644 --- a/playground/ios/NavigationTests/RNNTabBarControllerTest.m +++ b/playground/ios/NavigationTests/RNNTabBarControllerTest.m @@ -28,7 +28,7 @@ - (void)setUp { self.mockTabBarPresenter = [OCMockObject partialMockForObject:[[RNNBottomTabsPresenter alloc] init]]; self.mockChildViewController = [OCMockObject partialMockForObject:[RNNComponentViewController new]]; self.mockEventEmitter = [OCMockObject partialMockForObject:[RNNEventEmitter new]]; - self.originalUut = [[RNNBottomTabsController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initWithDict:@{}] defaultOptions:nil presenter:self.mockTabBarPresenter bottomTabPresenter:[BottomTabPresenterCreator createWithDefaultOptions:nil children:children] dotIndicatorPresenter:[[RNNDotIndicatorPresenter alloc] initWithDefaultOptions:nil] eventEmitter:self.mockEventEmitter childViewControllers:children bottomTabsAttacher:nil]; + self.originalUut = [[RNNBottomTabsController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initWithDict:@{}] defaultOptions:nil presenter:self.mockTabBarPresenter bottomTabPresenter:[BottomTabPresenterCreator createWithDefaultOptions:nil] dotIndicatorPresenter:[[RNNDotIndicatorPresenter alloc] initWithDefaultOptions:nil] eventEmitter:self.mockEventEmitter childViewControllers:children bottomTabsAttacher:nil]; self.uut = [OCMockObject partialMockForObject:self.originalUut]; OCMStub([self.uut selectedViewController]).andReturn(self.mockChildViewController); }