forked from wix/react-native-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBottomTabsBasePresenter.m
133 lines (108 loc) · 5.27 KB
/
BottomTabsBasePresenter.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#import "BottomTabsBasePresenter.h"
#import "RNNBottomTabsController.h"
#import "UIImage+utils.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 withDefault:0]];
if (withDefault.bottomTabs.currentTabId.hasValue) {
[bottomTabs setCurrentTabID:withDefault.bottomTabs.currentTabId.get];
}
if ([[withDefault.bottomTabs.titleDisplayMode withDefault:@"alwaysShow"]
isEqualToString:@"alwaysHide"]) {
[bottomTabs centerTabItems];
}
}
- (void)applyOptions:(RNNNavigationOptions *)options {
RNNBottomTabsController *bottomTabs = self.tabBarController;
RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
[bottomTabs setTabBarTestID:[withDefault.bottomTabs.testID withDefault:nil]];
[bottomTabs setTabBarVisible:[withDefault.bottomTabs.visible withDefault:YES]];
[bottomTabs.view setBackgroundColor:[withDefault.layout.backgroundColor withDefault:nil]];
[self applyBackgroundColor:[withDefault.bottomTabs.backgroundColor withDefault:nil]
translucent:[withDefault.bottomTabs.translucent withDefault:NO]];
[bottomTabs setTabBarHideShadow:[withDefault.bottomTabs.hideShadow withDefault:NO]];
[bottomTabs setTabBarStyle:[RCTConvert UIBarStyle:[withDefault.bottomTabs.barStyle
withDefault:@"default"]]];
[self applyTabBarBorder:withDefault.bottomTabs];
[self applyTabBarShadow:withDefault.bottomTabs.shadow];
}
- (void)mergeOptions:(RNNNavigationOptions *)mergeOptions
resolvedOptions:(RNNNavigationOptions *)currentOptions {
[super mergeOptions:mergeOptions resolvedOptions:currentOptions];
RNNBottomTabsController *bottomTabs = self.tabBarController;
RNNNavigationOptions *withDefault = [mergeOptions withDefault:[self defaultOptions]];
if (mergeOptions.bottomTabs.currentTabIndex.hasValue) {
[bottomTabs setCurrentTabIndex:mergeOptions.bottomTabs.currentTabIndex.get];
[mergeOptions.bottomTabs.currentTabIndex consume];
}
if (mergeOptions.bottomTabs.currentTabId.hasValue) {
[bottomTabs setCurrentTabID:mergeOptions.bottomTabs.currentTabId.get];
[mergeOptions.bottomTabs.currentTabId consume];
}
if (mergeOptions.bottomTabs.testID.hasValue) {
[bottomTabs setTabBarTestID:mergeOptions.bottomTabs.testID.get];
}
if (mergeOptions.bottomTabs.backgroundColor.hasValue) {
[self setTabBarBackgroundColor:mergeOptions.bottomTabs.backgroundColor.get];
}
if (mergeOptions.bottomTabs.barStyle.hasValue) {
[bottomTabs setTabBarStyle:[RCTConvert UIBarStyle:mergeOptions.bottomTabs.barStyle.get]];
}
if (mergeOptions.bottomTabs.translucent.hasValue) {
[bottomTabs setTabBarTranslucent:mergeOptions.bottomTabs.translucent.get];
}
if (mergeOptions.bottomTabs.hideShadow.hasValue) {
[bottomTabs setTabBarHideShadow:mergeOptions.bottomTabs.hideShadow.get];
}
if (mergeOptions.bottomTabs.visible.hasValue) {
if (mergeOptions.bottomTabs.animate.hasValue) {
[bottomTabs setTabBarVisible:mergeOptions.bottomTabs.visible.get
animated:[mergeOptions.bottomTabs.animate withDefault:NO]];
} else {
[bottomTabs setTabBarVisible:mergeOptions.bottomTabs.visible.get animated:NO];
}
}
if (mergeOptions.layout.backgroundColor.hasValue) {
[bottomTabs.view setBackgroundColor:mergeOptions.layout.backgroundColor.get];
}
if (mergeOptions.bottomTabs.borderColor.hasValue ||
mergeOptions.bottomTabs.borderWidth.hasValue) {
[self applyTabBarBorder:withDefault.bottomTabs];
}
if (mergeOptions.bottomTabs.shadow.hasValue) {
[self applyTabBarShadow:withDefault.bottomTabs.shadow];
}
}
- (RNNBottomTabsController *)tabBarController {
return (RNNBottomTabsController *)self.boundViewController;
}
- (UITabBar *)tabBar {
return self.tabBarController.tabBar;
}
- (void)applyTabBarBorder:(RNNBottomTabsOptions *)options {
if (options.borderColor.hasValue || options.borderWidth.hasValue) {
self.tabBar.backgroundImage = UIImage.new;
self.tabBar.shadowImage = [UIImage
imageWithSize:CGSizeMake(1, [[options.borderWidth withDefault:@(1)] floatValue])
color:[options.borderColor withDefault:UIColor.blackColor]];
}
}
- (void)applyTabBarShadow:(RNNShadowOptions *)options {
self.tabBar.layer.shadowRadius =
[options.radius withDefault:@(self.tabBar.layer.shadowRadius)].floatValue;
self.tabBar.layer.shadowColor =
[options.color withDefault:[UIColor colorWithCGColor:self.tabBar.layer.shadowColor]]
.CGColor;
self.tabBar.layer.shadowOpacity =
[options.opacity withDefault:@(self.tabBar.layer.shadowOpacity)].floatValue;
}
- (void)applyBackgroundColor:(UIColor *)backgroundColor translucent:(BOOL)translucent {
}
- (void)setTabBarBackgroundColor:(UIColor *)backgroundColor {
}
- (void)setTabBarTranslucent:(BOOL)translucent {
}
@end