Skip to content

Commit

Permalink
Fix bottomTabs.translucent option (#6025)
Browse files Browse the repository at this point in the history
* 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
yogevbd and guyca authored Mar 10, 2020
1 parent b01629c commit 6edbbf5
Show file tree
Hide file tree
Showing 17 changed files with 208 additions and 110 deletions.
4 changes: 2 additions & 2 deletions lib/ios/BottomTabsAppearancePresenter.h
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
41 changes: 38 additions & 3 deletions lib/ios/BottomTabsAppearancePresenter.m
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
20 changes: 20 additions & 0 deletions lib/ios/BottomTabsBasePresenter.h
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
95 changes: 95 additions & 0 deletions lib/ios/BottomTabsBasePresenter.m
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
2 changes: 2 additions & 0 deletions lib/ios/RNNBottomTabsOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@
@property (nonatomic, strong) Text* titleDisplayMode;
@property (nonatomic, strong) BottomTabsAttachMode* tabsAttachMode;

- (BOOL)shouldDrawBehind;

@end
6 changes: 6 additions & 0 deletions lib/ios/RNNBottomTabsOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ - (instancetype)initWithDict:(NSDictionary *)dict {
return self;
}

- (BOOL)shouldDrawBehind {
return [self.drawBehind getWithDefaultValue:NO] ||
[self.translucent getWithDefaultValue:NO] ||
![self.visible getWithDefaultValue:YES];
}

@end
10 changes: 2 additions & 8 deletions lib/ios/RNNBottomTabsPresenter.h
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
83 changes: 5 additions & 78 deletions lib/ios/RNNBottomTabsPresenter.m
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
18 changes: 9 additions & 9 deletions lib/ios/RNNComponentPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ - (void)applyOptions:(RNNNavigationOptions *)options {
}

- (void)applyOptionsOnInit:(RNNNavigationOptions *)options {
[super applyOptionsOnInit:options];

UIViewController* viewController = self.boundViewController;
RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
[super applyOptionsOnInit:options];

[viewController setDrawBehindTopBar:[withDefault.topBar.drawBehind getWithDefaultValue:NO]];
[viewController setDrawBehindTabBar:[withDefault.bottomTabs.drawBehind getWithDefaultValue:NO] || ![withDefault.bottomTabs.visible getWithDefaultValue:YES]];
UIViewController* viewController = self.boundViewController;
RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];

if ((withDefault.topBar.leftButtons || withDefault.topBar.rightButtons)) {
[_navigationButtons applyLeftButtons:withDefault.topBar.leftButtons rightButtons:withDefault.topBar.rightButtons defaultLeftButtonStyle:withDefault.topBar.leftButtonStyle defaultRightButtonStyle:withDefault.topBar.rightButtonStyle];
}
[viewController setDrawBehindTopBar:[withDefault.topBar shouldDrawBehind]];
[viewController setDrawBehindTabBar:[withDefault.bottomTabs shouldDrawBehind]];

if ((withDefault.topBar.leftButtons || withDefault.topBar.rightButtons)) {
[_navigationButtons applyLeftButtons:withDefault.topBar.leftButtons rightButtons:withDefault.topBar.rightButtons defaultLeftButtonStyle:withDefault.topBar.leftButtonStyle defaultRightButtonStyle:withDefault.topBar.rightButtonStyle];
}
}

- (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)currentOptions {
Expand Down
2 changes: 2 additions & 0 deletions lib/ios/RNNTopBarOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@
@property (nonatomic, strong) RNNButtonOptions* leftButtonStyle;
@property (nonatomic, strong) RNNButtonOptions* rightButtonStyle;

- (BOOL)shouldDrawBehind;

@end
6 changes: 6 additions & 0 deletions lib/ios/RNNTopBarOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,11 @@ - (instancetype)initWithDict:(NSDictionary *)dict {
return self;
}

- (BOOL)shouldDrawBehind {
return [self.drawBehind getWithDefaultValue:NO] ||
[self.background.translucent getWithDefaultValue:NO] ||
![self.visible getWithDefaultValue:YES] ||
[self.largeTitle.visible getWithDefaultValue:NO];
}

@end
8 changes: 8 additions & 0 deletions lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@
503A8A2623BD04410094D1C4 /* ElementTransitionsCreator.m in Sources */ = {isa = PBXBuildFile; fileRef = 503A8A2423BD04410094D1C4 /* ElementTransitionsCreator.m */; };
50415CBA20553B8E00BB682E /* RNNScreenTransition.h in Headers */ = {isa = PBXBuildFile; fileRef = 50415CB820553B8E00BB682E /* RNNScreenTransition.h */; };
50415CBB20553B8E00BB682E /* RNNScreenTransition.m in Sources */ = {isa = PBXBuildFile; fileRef = 50415CB920553B8E00BB682E /* RNNScreenTransition.m */; };
5041DC3E2417BBBA0033312F /* BottomTabsBasePresenter.h in Headers */ = {isa = PBXBuildFile; fileRef = 5041DC3C2417BBBA0033312F /* BottomTabsBasePresenter.h */; };
5041DC3F2417BBBA0033312F /* BottomTabsBasePresenter.m in Sources */ = {isa = PBXBuildFile; fileRef = 5041DC3D2417BBBA0033312F /* BottomTabsBasePresenter.m */; };
50451D052042DAEB00695F00 /* RNNPushAnimation.h in Headers */ = {isa = PBXBuildFile; fileRef = 50451D032042DAEB00695F00 /* RNNPushAnimation.h */; };
50451D062042DAEB00695F00 /* RNNPushAnimation.m in Sources */ = {isa = PBXBuildFile; fileRef = 50451D042042DAEB00695F00 /* RNNPushAnimation.m */; };
50451D092042E20600695F00 /* RNNAnimationsOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 50451D072042E20600695F00 /* RNNAnimationsOptions.h */; };
Expand Down Expand Up @@ -653,6 +655,8 @@
503A8A2423BD04410094D1C4 /* ElementTransitionsCreator.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ElementTransitionsCreator.m; sourceTree = "<group>"; };
50415CB820553B8E00BB682E /* RNNScreenTransition.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNScreenTransition.h; sourceTree = "<group>"; };
50415CB920553B8E00BB682E /* RNNScreenTransition.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNScreenTransition.m; sourceTree = "<group>"; };
5041DC3C2417BBBA0033312F /* BottomTabsBasePresenter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BottomTabsBasePresenter.h; sourceTree = "<group>"; };
5041DC3D2417BBBA0033312F /* BottomTabsBasePresenter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BottomTabsBasePresenter.m; sourceTree = "<group>"; };
50451D032042DAEB00695F00 /* RNNPushAnimation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNPushAnimation.h; sourceTree = "<group>"; };
50451D042042DAEB00695F00 /* RNNPushAnimation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNPushAnimation.m; sourceTree = "<group>"; };
50451D072042E20600695F00 /* RNNAnimationsOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNAnimationsOptions.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1395,6 +1399,8 @@
5022EDB82405226800852BA6 /* BottomTabAppearancePresenter.m */,
5022EDC324054C6100852BA6 /* BottomTabsAppearancePresenter.h */,
5022EDC424054C6100852BA6 /* BottomTabsAppearancePresenter.m */,
5041DC3C2417BBBA0033312F /* BottomTabsBasePresenter.h */,
5041DC3D2417BBBA0033312F /* BottomTabsBasePresenter.m */,
5022EDBB2405237100852BA6 /* BottomTabPresenterCreator.h */,
5022EDBC2405237100852BA6 /* BottomTabPresenterCreator.m */,
5022EDC724054C8A00852BA6 /* BottomTabsPresenterCreator.h */,
Expand Down Expand Up @@ -1705,6 +1711,7 @@
50E38DDD23A7A306009817F6 /* AnimatedImageView.h in Headers */,
7B4928081E70415400555040 /* RNNCommandsHandler.h in Headers */,
50495942216F5E5D006D2B81 /* NullBool.h in Headers */,
5041DC3E2417BBBA0033312F /* BottomTabsBasePresenter.h in Headers */,
263905AE1E4C6F440023D7D3 /* MMDrawerBarButtonItem.h in Headers */,
5012241621736667000F5F98 /* Color.h in Headers */,
7365071121E4B16F004E020F /* RCTConvert+UIBarButtonSystemItem.h in Headers */,
Expand Down Expand Up @@ -2199,6 +2206,7 @@
30987D71FB4FEEAC8D8978E8 /* DotIndicatorParser.m in Sources */,
50CED44E239EA78700C42EE2 /* TopBarAppearancePresenter.m in Sources */,
30987B23F288EB3A78B7F27C /* RNNDotIndicatorPresenter.m in Sources */,
5041DC3F2417BBBA0033312F /* BottomTabsBasePresenter.m in Sources */,
5022EDC224053C9F00852BA6 /* TabBarItemAppearanceCreator.m in Sources */,
507ACB1223F44D1E00829911 /* RNNComponentView.m in Sources */,
5017D9F3239D2FCB00B74047 /* BottomTabsOnSwitchToTabAttacher.m in Sources */,
Expand Down
Loading

0 comments on commit 6edbbf5

Please sign in to comment.