Skip to content

Commit

Permalink
[V2][iOS] Additional mergeOptions BottomTab Support (#4704)
Browse files Browse the repository at this point in the history
* Added missing mergeOptions for text, icon, selectedIcon, textColor, selectedTextColor, iconColor, selectedIconColor, badgeColor

* Minor changes
  • Loading branch information
Rav Sispal authored and yogevbd committed Feb 7, 2019
1 parent 3f92856 commit 2362655
Showing 1 changed file with 89 additions and 6 deletions.
95 changes: 89 additions & 6 deletions lib/ios/RNNBasePresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,116 @@ - (void)bindViewController:(UIViewController *)bindedViewController {
}

- (void)applyOptionsOnInit:(RNNNavigationOptions *)initialOptions {

}

- (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options {
UIViewController* viewController = self.bindedViewController;
if ((options.bottomTab.text.hasValue || options.bottomTab.icon.hasValue || options.bottomTab.selectedIcon.hasValue)) {

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

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

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

if (options.bottomTab.badgeColor.hasValue) {
UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
viewController.tabBarItem = tabItem;
}

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

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

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

if (options.bottomTab.selectedIconColor.hasValue) {
UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
viewController.tabBarItem = tabItem;
[options.bottomTab.text consume];
[options.bottomTab.icon consume];
[options.bottomTab.selectedIcon consume];
}
}

- (void)applyOptions:(RNNNavigationOptions *)options {
UIViewController* viewController = self.bindedViewController;

if (options.bottomTab.badge.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
[viewController rnn_setTabBarItemBadge:options.bottomTab.badge.get];
}

if (options.bottomTab.badgeColor.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
[viewController rnn_setTabBarItemBadgeColor:options.bottomTab.badgeColor.get];
}
}

- (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions defaultOptions:(RNNNavigationOptions *)defaultOptions {
UIViewController* viewController = self.bindedViewController;
if (newOptions.bottomTab.badge.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
[viewController rnn_setTabBarItemBadge:newOptions.bottomTab.badge.get];
}

if (newOptions.bottomTab.badgeColor.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
[viewController rnn_setTabBarItemBadgeColor:newOptions.bottomTab.badgeColor.get];
}

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

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

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

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

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

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

if (newOptions.bottomTab.selectedIconColor.hasValue) {
RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
viewController.tabBarItem = tabItem;
}
}


Expand Down

0 comments on commit 2362655

Please sign in to comment.