-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bottomTabs.translucent option (#6025)
* Fix translucent bottomTabs * Remove unnecessary safeAreaView from Root component * Add bottomTabsPresenter base class * Revert Root.js * DrawBehind when largeTitle is visible Co-authored-by: Guy Carmeli <[email protected]>
- Loading branch information
Showing
17 changed files
with
208 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#import "RNNBottomTabsPresenter.h" | ||
#import "BottomTabsBasePresenter.h" | ||
|
||
API_AVAILABLE(ios(13.0)) | ||
@interface BottomTabsAppearancePresenter : RNNBottomTabsPresenter | ||
@interface BottomTabsAppearancePresenter : BottomTabsBasePresenter | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,47 @@ | ||
#import "BottomTabsAppearancePresenter.h" | ||
#import "UIColor+RNNUtils.h" | ||
|
||
@implementation BottomTabsAppearancePresenter | ||
|
||
# pragma mark - public | ||
|
||
- (void)applyBackgroundColor:(UIColor *)backgroundColor translucent:(BOOL)translucent { | ||
if (translucent) [self setTabBarTranslucent:YES]; | ||
else if (backgroundColor.isTransparent) [self setTabBarTransparentBackground]; | ||
else if (backgroundColor) [self setTabBarBackgroundColor:backgroundColor]; | ||
else [self setTabBarDefaultBackground]; | ||
} | ||
|
||
- (void)setTabBarBackgroundColor:(UIColor *)backgroundColor { | ||
UITabBarController *bottomTabs = self.tabBarController; | ||
for (UIViewController* childViewController in bottomTabs.childViewControllers) { | ||
[self setTabBarOpaqueBackground]; | ||
for (UIViewController* childViewController in self.tabBarController.childViewControllers) | ||
childViewController.tabBarItem.standardAppearance.backgroundColor = backgroundColor; | ||
} | ||
} | ||
|
||
- (void)setTabBarTranslucent:(BOOL)translucent { | ||
if (translucent) [self setTabBarTranslucentBackground]; | ||
else [self setTabBarOpaqueBackground]; | ||
} | ||
|
||
# pragma mark - private | ||
|
||
- (void)setTabBarDefaultBackground { | ||
[self setTabBarOpaqueBackground]; | ||
} | ||
|
||
- (void)setTabBarTranslucentBackground { | ||
for (UIViewController* childViewController in self.tabBarController.childViewControllers) | ||
[childViewController.tabBarItem.standardAppearance configureWithDefaultBackground]; | ||
} | ||
|
||
- (void)setTabBarTransparentBackground { | ||
for (UIViewController* childViewController in self.tabBarController.childViewControllers) | ||
[childViewController.tabBarItem.standardAppearance configureWithTransparentBackground]; | ||
} | ||
|
||
- (void)setTabBarOpaqueBackground { | ||
for (UIViewController* childViewController in self.tabBarController.childViewControllers) | ||
[childViewController.tabBarItem.standardAppearance configureWithOpaqueBackground]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#import <Foundation/Foundation.h> | ||
#import "RNNBasePresenter.h" | ||
#import "UITabBarController+RNNOptions.h" | ||
#import "UIViewController+LayoutProtocol.h" | ||
#import "UIViewController+Utils.h" | ||
#import "UIColor+RNNUtils.h" | ||
|
||
@interface BottomTabsBasePresenter : RNNBasePresenter | ||
|
||
- (void)applyBackgroundColor:(UIColor *)backgroundColor translucent:(BOOL)translucent; | ||
|
||
- (void)setTabBarBackgroundColor:(UIColor *)backgroundColor; | ||
|
||
- (void)setTabBarTranslucent:(BOOL)translucent; | ||
|
||
- (UITabBarController *)tabBarController; | ||
|
||
- (UITabBar *)tabBar; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#import "BottomTabsBasePresenter.h" | ||
|
||
@implementation BottomTabsBasePresenter | ||
|
||
- (void)applyOptionsOnInit:(RNNNavigationOptions *)options { | ||
[super applyOptionsOnInit:options]; | ||
UITabBarController *bottomTabs = self.tabBarController; | ||
RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]]; | ||
[bottomTabs setCurrentTabIndex:[withDefault.bottomTabs.currentTabIndex getWithDefaultValue:0]]; | ||
if ([[withDefault.bottomTabs.titleDisplayMode getWithDefaultValue:@"alwaysShow"] isEqualToString:@"alwaysHide"]) { | ||
[bottomTabs centerTabItems]; | ||
} | ||
} | ||
|
||
- (void)applyOptions:(RNNNavigationOptions *)options { | ||
UITabBarController *bottomTabs = self.tabBarController; | ||
RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]]; | ||
|
||
[bottomTabs setTabBarTestID:[withDefault.bottomTabs.testID getWithDefaultValue:nil]]; | ||
[bottomTabs setTabBarVisible:[withDefault.bottomTabs.visible getWithDefaultValue:YES] animated:[withDefault.bottomTabs.animate getWithDefaultValue:NO]]; | ||
|
||
[bottomTabs.view setBackgroundColor:[withDefault.layout.backgroundColor getWithDefaultValue:nil]]; | ||
[self applyBackgroundColor:[withDefault.bottomTabs.backgroundColor getWithDefaultValue:nil] translucent:[withDefault.bottomTabs.translucent getWithDefaultValue:NO]]; | ||
[bottomTabs setTabBarHideShadow:[withDefault.bottomTabs.hideShadow getWithDefaultValue:NO]]; | ||
[bottomTabs setTabBarStyle:[RCTConvert UIBarStyle:[withDefault.bottomTabs.barStyle getWithDefaultValue:@"default"]]]; | ||
} | ||
|
||
- (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)currentOptions { | ||
[super mergeOptions:options resolvedOptions:currentOptions]; | ||
UITabBarController *bottomTabs = self.tabBarController; | ||
|
||
if (options.bottomTabs.currentTabIndex.hasValue) { | ||
[bottomTabs setCurrentTabIndex:options.bottomTabs.currentTabIndex.get]; | ||
[options.bottomTabs.currentTabIndex consume]; | ||
} | ||
|
||
if (options.bottomTabs.currentTabId.hasValue) { | ||
[bottomTabs setCurrentTabID:options.bottomTabs.currentTabId.get]; | ||
[options.bottomTabs.currentTabId consume]; | ||
} | ||
|
||
if (options.bottomTabs.testID.hasValue) { | ||
[bottomTabs setTabBarTestID:options.bottomTabs.testID.get]; | ||
} | ||
|
||
if (options.bottomTabs.backgroundColor.hasValue) { | ||
[self setTabBarBackgroundColor:options.bottomTabs.backgroundColor.get]; | ||
} | ||
|
||
if (options.bottomTabs.barStyle.hasValue) { | ||
[bottomTabs setTabBarStyle:[RCTConvert UIBarStyle:options.bottomTabs.barStyle.get]]; | ||
} | ||
|
||
if (options.bottomTabs.translucent.hasValue) { | ||
[bottomTabs setTabBarTranslucent:options.bottomTabs.translucent.get]; | ||
} | ||
|
||
if (options.bottomTabs.hideShadow.hasValue) { | ||
[bottomTabs setTabBarHideShadow:options.bottomTabs.hideShadow.get]; | ||
} | ||
|
||
if (options.bottomTabs.visible.hasValue) { | ||
if (options.bottomTabs.animate.hasValue) { | ||
[bottomTabs setTabBarVisible:options.bottomTabs.visible.get animated:[options.bottomTabs.animate getWithDefaultValue:NO]]; | ||
} else { | ||
[bottomTabs setTabBarVisible:options.bottomTabs.visible.get animated:NO]; | ||
} | ||
} | ||
|
||
if (options.layout.backgroundColor.hasValue) { | ||
[bottomTabs.view setBackgroundColor:options.layout.backgroundColor.get]; | ||
} | ||
} | ||
|
||
- (UITabBarController *)tabBarController { | ||
return (UITabBarController *)self.boundViewController; | ||
} | ||
|
||
- (UITabBar *)tabBar { | ||
return self.tabBarController.tabBar; | ||
} | ||
|
||
- (void)applyBackgroundColor:(UIColor *)backgroundColor translucent:(BOOL)translucent { | ||
|
||
} | ||
|
||
- (void)setTabBarBackgroundColor:(UIColor *)backgroundColor { | ||
|
||
} | ||
|
||
- (void)setTabBarTranslucent:(BOOL)translucent { | ||
|
||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,5 @@ | ||
#import "RNNBasePresenter.h" | ||
#import "BottomTabsBasePresenter.h" | ||
|
||
@interface RNNBottomTabsPresenter : RNNBasePresenter | ||
|
||
- (void)setTabBarBackgroundColor:(UIColor *)backgroundColor; | ||
|
||
- (UITabBarController *)tabBarController; | ||
|
||
- (UITabBar *)tabBar; | ||
@interface RNNBottomTabsPresenter : BottomTabsBasePresenter | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,18 @@ | ||
#import "RNNBottomTabsPresenter.h" | ||
#import "UITabBarController+RNNOptions.h" | ||
#import "UIViewController+LayoutProtocol.h" | ||
#import "UIViewController+Utils.h" | ||
|
||
@implementation RNNBottomTabsPresenter | ||
|
||
- (void)applyOptionsOnInit:(RNNNavigationOptions *)options { | ||
[super applyOptionsOnInit:options]; | ||
UITabBarController *bottomTabs = self.tabBarController; | ||
RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]]; | ||
[bottomTabs setCurrentTabIndex:[withDefault.bottomTabs.currentTabIndex getWithDefaultValue:0]]; | ||
if ([[withDefault.bottomTabs.titleDisplayMode getWithDefaultValue:@"alwaysShow"] isEqualToString:@"alwaysHide"]) { | ||
[bottomTabs centerTabItems]; | ||
} | ||
} | ||
|
||
- (void)applyOptions:(RNNNavigationOptions *)options { | ||
UITabBarController *bottomTabs = self.tabBarController; | ||
RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]]; | ||
|
||
[bottomTabs setTabBarTestID:[withDefault.bottomTabs.testID getWithDefaultValue:nil]]; | ||
[bottomTabs setTabBarVisible:[withDefault.bottomTabs.visible getWithDefaultValue:YES] animated:[withDefault.bottomTabs.animate getWithDefaultValue:NO]]; | ||
|
||
[bottomTabs.view setBackgroundColor:[withDefault.layout.backgroundColor getWithDefaultValue:nil]]; | ||
[self setTabBarBackgroundColor:[withDefault.bottomTabs.backgroundColor getWithDefaultValue:UIColor.whiteColor]]; | ||
[bottomTabs setTabBarTranslucent:[withDefault.bottomTabs.translucent getWithDefaultValue:NO]]; | ||
[bottomTabs setTabBarHideShadow:[withDefault.bottomTabs.hideShadow getWithDefaultValue:NO]]; | ||
[bottomTabs setTabBarStyle:[RCTConvert UIBarStyle:[withDefault.bottomTabs.barStyle getWithDefaultValue:@"default"]]]; | ||
} | ||
|
||
- (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)currentOptions { | ||
[super mergeOptions:options resolvedOptions:currentOptions]; | ||
UITabBarController *bottomTabs = self.tabBarController; | ||
|
||
if (options.bottomTabs.currentTabIndex.hasValue) { | ||
[bottomTabs setCurrentTabIndex:options.bottomTabs.currentTabIndex.get]; | ||
[options.bottomTabs.currentTabIndex consume]; | ||
} | ||
|
||
if (options.bottomTabs.currentTabId.hasValue) { | ||
[bottomTabs setCurrentTabID:options.bottomTabs.currentTabId.get]; | ||
[options.bottomTabs.currentTabId consume]; | ||
} | ||
|
||
if (options.bottomTabs.testID.hasValue) { | ||
[bottomTabs setTabBarTestID:options.bottomTabs.testID.get]; | ||
} | ||
|
||
if (options.bottomTabs.backgroundColor.hasValue) { | ||
[self setTabBarBackgroundColor:options.bottomTabs.backgroundColor.get]; | ||
} | ||
|
||
if (options.bottomTabs.barStyle.hasValue) { | ||
[bottomTabs setTabBarStyle:[RCTConvert UIBarStyle:options.bottomTabs.barStyle.get]]; | ||
} | ||
|
||
if (options.bottomTabs.translucent.hasValue) { | ||
[bottomTabs setTabBarTranslucent:options.bottomTabs.translucent.get]; | ||
} | ||
|
||
if (options.bottomTabs.hideShadow.hasValue) { | ||
[bottomTabs setTabBarHideShadow:options.bottomTabs.hideShadow.get]; | ||
} | ||
|
||
if (options.bottomTabs.visible.hasValue) { | ||
if (options.bottomTabs.animate.hasValue) { | ||
[bottomTabs setTabBarVisible:options.bottomTabs.visible.get animated:[options.bottomTabs.animate getWithDefaultValue:NO]]; | ||
} else { | ||
[bottomTabs setTabBarVisible:options.bottomTabs.visible.get animated:NO]; | ||
} | ||
} | ||
|
||
if (options.layout.backgroundColor.hasValue) { | ||
[bottomTabs.view setBackgroundColor:options.layout.backgroundColor.get]; | ||
} | ||
- (void)applyBackgroundColor:(UIColor *)backgroundColor translucent:(BOOL)translucent { | ||
[self setTabBarTranslucent:translucent]; | ||
[self setTabBarBackgroundColor:backgroundColor]; | ||
} | ||
|
||
- (void)setTabBarBackgroundColor:(UIColor *)backgroundColor { | ||
self.tabBar.barTintColor = backgroundColor; | ||
} | ||
|
||
- (UITabBarController *)tabBarController { | ||
return (UITabBarController *)self.boundViewController; | ||
} | ||
|
||
- (UITabBar *)tabBar { | ||
return self.tabBarController.tabBar; | ||
- (void)setTabBarTranslucent:(BOOL)translucent { | ||
self.tabBar.translucent = translucent; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.