|
@@ -2,6 +2,7 @@
|
2
|
2
|
#import <React/RCTConvert.h>
|
3
|
3
|
#import "RNNNavigationController.h"
|
4
|
4
|
#import "RNNTabBarController.h"
|
|
5
|
+#import "RNNTopBarOptions.h"
|
5
|
6
|
|
6
|
7
|
const NSInteger BLUR_STATUS_TAG = 78264801;
|
7
|
8
|
const NSInteger BLUR_TOPBAR_TAG = 78264802;
|
|
@@ -14,89 +15,116 @@ const NSInteger BLUR_TOPBAR_TAG = 78264802;
|
14
|
15
|
|
15
|
16
|
-(instancetype)initWithDict:(NSDictionary *)navigationOptions {
|
16
|
17
|
self = [super init];
|
17
|
|
- self.topBarBackgroundColor = [navigationOptions objectForKey:@"topBarBackgroundColor"];
|
18
|
18
|
self.statusBarHidden = [navigationOptions objectForKey:@"statusBarHidden"];
|
19
|
|
- self.title = [navigationOptions objectForKey:@"title"];
|
20
|
|
- self.topBarTextColor = [navigationOptions objectForKey:@"topBarTextColor"];
|
21
|
19
|
self.screenBackgroundColor = [navigationOptions objectForKey:@"screenBackgroundColor"];
|
22
|
|
- self.topBarTextFontFamily = [navigationOptions objectForKey:@"topBarTextFontFamily"];
|
23
|
|
- self.topBarHidden = [navigationOptions objectForKey:@"topBarHidden"];
|
24
|
|
- self.topBarHideOnScroll = [navigationOptions objectForKey:@"topBarHideOnScroll"];
|
25
|
|
- self.topBarButtonColor = [navigationOptions objectForKey:@"topBarButtonColor"];
|
26
|
|
- self.topBarTranslucent = [navigationOptions objectForKey:@"topBarTranslucent"];
|
27
|
20
|
self.tabBadge = [navigationOptions objectForKey:@"tabBadge"];
|
28
|
|
- self.topBarTextFontSize = [navigationOptions objectForKey:@"topBarTextFontSize"];
|
29
|
21
|
self.orientation = [navigationOptions objectForKey:@"orientation"];
|
30
|
22
|
self.leftButtons = [navigationOptions objectForKey:@"leftButtons"];
|
31
|
23
|
self.rightButtons = [navigationOptions objectForKey:@"rightButtons"];
|
32
|
|
- self.topBarNoBorder = [navigationOptions objectForKey:@"topBarNoBorder"];
|
33
|
24
|
self.tabBarHidden = [navigationOptions objectForKey:@"tabBarHidden"];
|
34
|
|
- self.topBarBlur = [navigationOptions objectForKey:@"topBarBlur"];
|
35
|
|
- self.animateTopBarHide = [navigationOptions objectForKey:@"animateTopBarHide"];
|
36
|
|
-
|
|
25
|
+ self.topBar = [[RNNTopBarOptions alloc] initWithDict:[navigationOptions objectForKey:@"topBar"]];
|
|
26
|
+
|
37
|
27
|
return self;
|
38
|
28
|
}
|
39
|
29
|
|
40
|
30
|
-(void)mergeWith:(NSDictionary *)otherOptions {
|
41
|
31
|
for (id key in otherOptions) {
|
42
|
|
- [self setValue:[otherOptions objectForKey:key] forKey:key];
|
|
32
|
+ if ([key isEqualToString:@"topBar"]) {
|
|
33
|
+ [self.topBar mergeWith:[otherOptions objectForKey:@"topBar"]];
|
|
34
|
+ } else {
|
|
35
|
+ [self setValue:[otherOptions objectForKey:key] forKey:key];
|
|
36
|
+ }
|
43
|
37
|
}
|
44
|
38
|
}
|
45
|
39
|
|
46
|
40
|
-(void)applyOn:(UIViewController*)viewController {
|
47
|
|
- if (self.topBarBackgroundColor) {
|
48
|
|
- UIColor* backgroundColor = [RCTConvert UIColor:self.topBarBackgroundColor];
|
49
|
|
- viewController.navigationController.navigationBar.barTintColor = backgroundColor;
|
50
|
|
- } else {
|
51
|
|
- viewController.navigationController.navigationBar.barTintColor = nil;
|
52
|
|
- }
|
|
41
|
+ if (self.topBar) {
|
|
42
|
+ if(self.topBar.backgroundColor) {
|
|
43
|
+ UIColor* backgroundColor = [RCTConvert UIColor:self.topBar.backgroundColor];
|
|
44
|
+ viewController.navigationController.navigationBar.barTintColor = backgroundColor;
|
|
45
|
+ } else {
|
|
46
|
+ viewController.navigationController.navigationBar.barTintColor = nil;
|
|
47
|
+ }
|
|
48
|
+
|
|
49
|
+ if (self.topBar.title) {
|
|
50
|
+ viewController.navigationItem.title = self.topBar.title;
|
|
51
|
+ }
|
|
52
|
+
|
|
53
|
+ if (self.topBar.textFontFamily || self.topBar.textFontSize || self.topBar.textColor) {
|
|
54
|
+ NSMutableDictionary* navigationBarTitleTextAttributes = [NSMutableDictionary new];
|
|
55
|
+ if (self.topBar.textColor) {
|
|
56
|
+ navigationBarTitleTextAttributes[NSForegroundColorAttributeName] = [RCTConvert UIColor:[self.topBar valueForKey:@"textColor"]];
|
|
57
|
+ }
|
|
58
|
+ if (self.topBar.textFontFamily){
|
|
59
|
+ if(self.topBar.textFontSize) {
|
|
60
|
+ navigationBarTitleTextAttributes[NSFontAttributeName] = [UIFont fontWithName:self.topBar.textFontFamily size:[self.topBar.textFontSize floatValue]];
|
|
61
|
+ } else {
|
|
62
|
+ navigationBarTitleTextAttributes[NSFontAttributeName] = [UIFont fontWithName:self.topBar.textFontFamily size:20];
|
|
63
|
+ }
|
|
64
|
+ } else if (self.topBar.textFontSize) {
|
|
65
|
+ navigationBarTitleTextAttributes[NSFontAttributeName] = [UIFont systemFontOfSize:[self.topBar.textFontSize floatValue]];
|
|
66
|
+ }
|
|
67
|
+ viewController.navigationController.navigationBar.titleTextAttributes = navigationBarTitleTextAttributes;
|
|
68
|
+ }
|
53
|
69
|
|
54
|
|
- if (self.title) {
|
55
|
|
- viewController.navigationItem.title = self.title;
|
56
|
|
- }
|
57
|
70
|
|
58
|
|
- if (self.topBarTextFontFamily || self.topBarTextColor || self.topBarTextFontSize){
|
59
|
|
- NSMutableDictionary* navigationBarTitleTextAttributes = [NSMutableDictionary new];
|
60
|
|
- if (self.topBarTextColor) {
|
61
|
|
- navigationBarTitleTextAttributes[NSForegroundColorAttributeName] = [RCTConvert UIColor:self.topBarTextColor];
|
|
71
|
+ if (self.topBar.hidden){
|
|
72
|
+ [viewController.navigationController setNavigationBarHidden:[self.topBar.hidden boolValue] animated:[self.topBar.animateHide boolValue]];
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+ if (self.topBar.hideOnScroll) {
|
|
76
|
+ viewController.navigationController.hidesBarsOnSwipe = [self.topBar.hideOnScroll boolValue];
|
|
77
|
+ }
|
|
78
|
+
|
|
79
|
+ if (self.topBar.buttonColor) {
|
|
80
|
+ UIColor* buttonColor = [RCTConvert UIColor:self.topBar.buttonColor];
|
|
81
|
+ viewController.navigationController.navigationBar.tintColor = buttonColor;
|
|
82
|
+ } else {
|
|
83
|
+ viewController.navigationController.navigationBar.tintColor = nil;
|
62
|
84
|
}
|
63
|
|
- if (self.topBarTextFontFamily){
|
64
|
|
- if(self.topBarTextFontSize) {
|
65
|
|
- navigationBarTitleTextAttributes[NSFontAttributeName] = [UIFont fontWithName:self.topBarTextFontFamily size:[self.topBarTextFontSize floatValue]];
|
|
85
|
+
|
|
86
|
+ if ([self.topBar.blur boolValue]) {
|
|
87
|
+ if (![viewController.navigationController.navigationBar viewWithTag:BLUR_TOPBAR_TAG]) {
|
|
88
|
+
|
|
89
|
+ [viewController.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
|
|
90
|
+ viewController.navigationController.navigationBar.shadowImage = [UIImage new];
|
|
91
|
+ UIVisualEffectView *blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
|
|
92
|
+ CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
|
|
93
|
+ blur.frame = CGRectMake(0, -1 * statusBarFrame.size.height, viewController.navigationController.navigationBar.frame.size.width, viewController.navigationController.navigationBar.frame.size.height + statusBarFrame.size.height);
|
|
94
|
+ blur.userInteractionEnabled = NO;
|
|
95
|
+ blur.tag = BLUR_TOPBAR_TAG;
|
|
96
|
+ [viewController.navigationController.navigationBar insertSubview:blur atIndex:0];
|
|
97
|
+ [viewController.navigationController.navigationBar sendSubviewToBack:blur];
|
|
98
|
+ }
|
|
99
|
+ } else {
|
|
100
|
+ UIView *blur = [viewController.navigationController.navigationBar viewWithTag:BLUR_TOPBAR_TAG];
|
|
101
|
+ if (blur) {
|
|
102
|
+ [viewController.navigationController.navigationBar setBackgroundImage: nil forBarMetrics:UIBarMetricsDefault];
|
|
103
|
+ viewController.navigationController.navigationBar.shadowImage = nil;
|
|
104
|
+ [blur removeFromSuperview];
|
|
105
|
+ }
|
|
106
|
+ }
|
|
107
|
+
|
|
108
|
+ if (self.topBar.translucent) {
|
|
109
|
+ viewController.navigationController.navigationBar.translucent = [self.topBar.translucent boolValue];
|
|
110
|
+ }
|
|
111
|
+
|
|
112
|
+ if (self.topBar.noBorder) {
|
|
113
|
+ if ([self.topBar.noBorder boolValue]) {
|
|
114
|
+ viewController.navigationController.navigationBar
|
|
115
|
+ .shadowImage = [[UIImage alloc] init];
|
66
|
116
|
} else {
|
67
|
|
- navigationBarTitleTextAttributes[NSFontAttributeName] = [UIFont fontWithName:self.topBarTextFontFamily size:20];
|
|
117
|
+ viewController.navigationController.navigationBar
|
|
118
|
+ .shadowImage = nil;
|
68
|
119
|
}
|
69
|
|
- } else if (self.topBarTextFontSize) {
|
70
|
|
- navigationBarTitleTextAttributes[NSFontAttributeName] = [UIFont systemFontOfSize:[self.topBarTextFontSize floatValue]];
|
71
|
120
|
}
|
72
|
|
- viewController.navigationController.navigationBar.titleTextAttributes = navigationBarTitleTextAttributes;
|
73
|
121
|
}
|
74
|
|
-
|
|
122
|
+
|
75
|
123
|
if (self.screenBackgroundColor) {
|
76
|
124
|
UIColor* screenColor = [RCTConvert UIColor:self.screenBackgroundColor];
|
77
|
125
|
viewController.view.backgroundColor = screenColor;
|
78
|
126
|
}
|
79
|
|
-
|
80
|
|
- if (self.topBarHidden){
|
81
|
|
- [viewController.navigationController setNavigationBarHidden:[self.topBarHidden boolValue] animated:[self.animateTopBarHide boolValue]];
|
82
|
|
- }
|
83
|
|
-
|
84
|
|
- if (self.topBarHideOnScroll) {
|
85
|
|
- BOOL topBarHideOnScrollBool = [self.topBarHideOnScroll boolValue];
|
86
|
|
- if (topBarHideOnScrollBool) {
|
87
|
|
- viewController.navigationController.hidesBarsOnSwipe = YES;
|
88
|
|
- } else {
|
89
|
|
- viewController.navigationController.hidesBarsOnSwipe = NO;
|
90
|
|
- }
|
91
|
|
- }
|
92
|
|
-
|
93
|
|
- if (self.topBarButtonColor) {
|
94
|
|
- UIColor* buttonColor = [RCTConvert UIColor:self.topBarButtonColor];
|
95
|
|
- viewController.navigationController.navigationBar.tintColor = buttonColor;
|
96
|
|
- } else {
|
97
|
|
- viewController.navigationController.navigationBar.tintColor = nil;
|
98
|
|
- }
|
99
|
|
-
|
|
127
|
+
|
100
|
128
|
if (self.tabBadge) {
|
101
|
129
|
NSString *badge = [RCTConvert NSString:self.tabBadge];
|
102
|
130
|
if (viewController.navigationController) {
|
|
@@ -105,25 +133,7 @@ const NSInteger BLUR_TOPBAR_TAG = 78264802;
|
105
|
133
|
viewController.tabBarItem.badgeValue = badge;
|
106
|
134
|
}
|
107
|
135
|
}
|
108
|
|
-
|
109
|
|
- if (self.topBarTranslucent) {
|
110
|
|
- if ([self.topBarTranslucent boolValue]) {
|
111
|
|
- viewController.navigationController.navigationBar.translucent = YES;
|
112
|
|
- } else {
|
113
|
|
- viewController.navigationController.navigationBar.translucent = NO;
|
114
|
|
- }
|
115
|
|
- }
|
116
|
|
-
|
117
|
|
- if (self.topBarNoBorder) {
|
118
|
|
- if ([self.topBarNoBorder boolValue]) {
|
119
|
|
- viewController.navigationController.navigationBar
|
120
|
|
- .shadowImage = [[UIImage alloc] init];
|
121
|
|
- } else {
|
122
|
|
- viewController.navigationController.navigationBar
|
123
|
|
- .shadowImage = nil;
|
124
|
|
- }
|
125
|
|
- }
|
126
|
|
-
|
|
136
|
+
|
127
|
137
|
if (self.statusBarBlur) {
|
128
|
138
|
UIView* curBlurView = [viewController.view viewWithTag:BLUR_STATUS_TAG];
|
129
|
139
|
if ([self.statusBarBlur boolValue]) {
|
|
@@ -139,30 +149,6 @@ const NSInteger BLUR_TOPBAR_TAG = 78264802;
|
139
|
149
|
}
|
140
|
150
|
}
|
141
|
151
|
}
|
142
|
|
-
|
143
|
|
- if (self.topBarBlur && [self.topBarBlur boolValue]) {
|
144
|
|
-
|
145
|
|
- if (![viewController.navigationController.navigationBar viewWithTag:BLUR_TOPBAR_TAG]) {
|
146
|
|
-
|
147
|
|
- [viewController.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
|
148
|
|
- viewController.navigationController.navigationBar.shadowImage = [UIImage new];
|
149
|
|
- UIVisualEffectView *blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
|
150
|
|
- CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
|
151
|
|
- blur.frame = CGRectMake(0, -1 * statusBarFrame.size.height, viewController.navigationController.navigationBar.frame.size.width, viewController.navigationController.navigationBar.frame.size.height + statusBarFrame.size.height);
|
152
|
|
- blur.userInteractionEnabled = NO;
|
153
|
|
- blur.tag = BLUR_TOPBAR_TAG;
|
154
|
|
- [viewController.navigationController.navigationBar insertSubview:blur atIndex:0];
|
155
|
|
- [viewController.navigationController.navigationBar sendSubviewToBack:blur];
|
156
|
|
- }
|
157
|
|
-
|
158
|
|
- } else {
|
159
|
|
- UIView *blur = [viewController.navigationController.navigationBar viewWithTag:BLUR_TOPBAR_TAG];
|
160
|
|
- if (blur) {
|
161
|
|
- [viewController.navigationController.navigationBar setBackgroundImage: nil forBarMetrics:UIBarMetricsDefault];
|
162
|
|
- viewController.navigationController.navigationBar.shadowImage = nil;
|
163
|
|
- [blur removeFromSuperview];
|
164
|
|
- }
|
165
|
|
- }
|
166
|
152
|
}
|
167
|
153
|
|
168
|
154
|
- (UIInterfaceOrientationMask)supportedOrientations {
|
|
@@ -187,7 +173,7 @@ const NSInteger BLUR_TOPBAR_TAG = 78264802;
|
187
|
173
|
}
|
188
|
174
|
}
|
189
|
175
|
}
|
190
|
|
-
|
|
176
|
+
|
191
|
177
|
return supportedOrientationsMask;
|
192
|
178
|
}
|
193
|
179
|
|