forked from wix/react-native-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBottomTabsAppearancePresenter.m
88 lines (76 loc) · 3.1 KB
/
BottomTabsAppearancePresenter.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
#import "BottomTabsAppearancePresenter.h"
#import "UIColor+RNNUtils.h"
#import "UIImage+Utils.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)applyTabBarBorder:(RNNBottomTabsOptions *)options {
if (options.borderColor.hasValue || options.borderWidth.hasValue) {
for (UIViewController *childViewController in self.tabBarController.childViewControllers)
childViewController.tabBarItem.standardAppearance.shadowImage = [UIImage
imageWithSize:CGSizeMake(1.0, [[options.borderWidth withDefault:@(0.1)] floatValue])
color:[options.borderColor withDefault:UIColor.blackColor]];
}
}
- (void)setTabBarBackgroundColor:(UIColor *)backgroundColor {
[self setTabBarOpaqueBackground];
for (UIViewController *childViewController in self.tabBarController.childViewControllers) {
childViewController.tabBarItem.standardAppearance.backgroundColor = backgroundColor;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000
if (@available(iOS 15.0, *)) {
childViewController.tabBarItem.scrollEdgeAppearance.backgroundColor = backgroundColor;
}
#endif
}
}
- (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];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000
if (@available(iOS 15.0, *)) {
[childViewController.tabBarItem.scrollEdgeAppearance configureWithDefaultBackground];
}
#endif
}
}
- (void)setTabBarTransparentBackground {
for (UIViewController *childViewController in self.tabBarController.childViewControllers) {
[childViewController.tabBarItem.standardAppearance configureWithTransparentBackground];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000
if (@available(iOS 15.0, *)) {
[childViewController.tabBarItem
.scrollEdgeAppearance configureWithTransparentBackground];
}
#endif
}
}
- (void)setTabBarOpaqueBackground {
for (UIViewController *childViewController in self.tabBarController.childViewControllers) {
[childViewController.tabBarItem.standardAppearance configureWithOpaqueBackground];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000
if (@available(iOS 15.0, *)) {
[childViewController.tabBarItem.scrollEdgeAppearance configureWithOpaqueBackground];
}
#endif
}
}
@end