Browse Source

[Breaking] Status bar options (#3245)

* refactored status bar options iOS

* [Breaking] Pull StatusBar styles to separate object
Guy Carmeli 6 years ago
parent
commit
98c6a6c205
No account linked to committer's email address

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/parse/Options.java View File

36
         result.animations = AnimationsOptions.parse(json.optJSONObject("animations"));
36
         result.animations = AnimationsOptions.parse(json.optJSONObject("animations"));
37
         result.screenBackgroundColor = ColorParser.parse(json, "screenBackgroundColor");
37
         result.screenBackgroundColor = ColorParser.parse(json, "screenBackgroundColor");
38
         result.modal = ModalOptions.parse(json);
38
         result.modal = ModalOptions.parse(json);
39
-        result.statusBar = StatusBarOptions.parse(json);
39
+        result.statusBar = StatusBarOptions.parse(json.optJSONObject("statusBar"));
40
 
40
 
41
         return result.withDefaultOptions(defaultOptions);
41
         return result.withDefaultOptions(defaultOptions);
42
     }
42
     }

+ 2
- 2
lib/android/app/src/main/java/com/reactnativenavigation/parse/StatusBarOptions.java View File

39
         StatusBarOptions result = new StatusBarOptions();
39
         StatusBarOptions result = new StatusBarOptions();
40
         if (json == null) return result;
40
         if (json == null) return result;
41
 
41
 
42
-        result.backgroundColor = ColorParser.parse(json, "statusBarBackgroundColor");
43
-        result.textColorScheme = TextColorScheme.fromString(json.optString("statusBarStyle"));
42
+        result.backgroundColor = ColorParser.parse(json, "backgroundColor");
43
+        result.textColorScheme = TextColorScheme.fromString(json.optString("style"));
44
 
44
 
45
         return result;
45
         return result;
46
     }
46
     }

+ 2
- 5
lib/ios/RNNNavigationOptions.h View File

8
 #import "RNNOverlayOptions.h"
8
 #import "RNNOverlayOptions.h"
9
 #import "RNNAnimationOptions.h"
9
 #import "RNNAnimationOptions.h"
10
 #import "RNNTransitionsOptions.h"
10
 #import "RNNTransitionsOptions.h"
11
+#import "RNNStatusBarOptions.h"
11
 
12
 
12
-extern const NSInteger BLUR_STATUS_TAG;
13
 extern const NSInteger BLUR_TOPBAR_TAG;
13
 extern const NSInteger BLUR_TOPBAR_TAG;
14
 extern const NSInteger TOP_BAR_TRANSPARENT_TAG;
14
 extern const NSInteger TOP_BAR_TRANSPARENT_TAG;
15
 
15
 
24
 @property (nonatomic, strong) RNNOverlayOptions* overlay;
24
 @property (nonatomic, strong) RNNOverlayOptions* overlay;
25
 @property (nonatomic, strong) RNNAnimationOptions* customTransition;
25
 @property (nonatomic, strong) RNNAnimationOptions* customTransition;
26
 @property (nonatomic, strong) RNNTransitionsOptions* animations;
26
 @property (nonatomic, strong) RNNTransitionsOptions* animations;
27
+@property (nonatomic, strong) RNNStatusBarOptions* statusBar;
27
 
28
 
28
 
29
 
29
-@property (nonatomic, strong) NSNumber* statusBarHidden;
30
 @property (nonatomic, strong) NSNumber* screenBackgroundColor;
30
 @property (nonatomic, strong) NSNumber* screenBackgroundColor;
31
 @property (nonatomic, strong) NSMutableDictionary* originalTopBarImages;
31
 @property (nonatomic, strong) NSMutableDictionary* originalTopBarImages;
32
 @property (nonatomic, strong) NSString* backButtonTransition;
32
 @property (nonatomic, strong) NSString* backButtonTransition;
33
 @property (nonatomic, strong) id orientation;
33
 @property (nonatomic, strong) id orientation;
34
-@property (nonatomic, strong) NSNumber* statusBarBlur;
35
-@property (nonatomic, strong) NSNumber* statusBarHideWithTopBar;
36
-@property (nonatomic, strong) NSString* statusBarStyle;
37
 @property (nonatomic, strong) NSNumber* popGesture;
34
 @property (nonatomic, strong) NSNumber* popGesture;
38
 @property (nonatomic, strong) NSDictionary* backgroundImage;
35
 @property (nonatomic, strong) NSDictionary* backgroundImage;
39
 @property (nonatomic, strong) NSDictionary* rootBackgroundImage;
36
 @property (nonatomic, strong) NSDictionary* rootBackgroundImage;

+ 2
- 20
lib/ios/RNNNavigationOptions.m View File

48
 	[self.bottomTab applyOn:viewController];
48
 	[self.bottomTab applyOn:viewController];
49
 	[self.sideMenu applyOn:viewController];
49
 	[self.sideMenu applyOn:viewController];
50
 	[self.overlay applyOn:viewController];
50
 	[self.overlay applyOn:viewController];
51
+	[self.statusBar applyOn:viewController];
52
+	
51
 	[self applyOtherOptionsOn:viewController];
53
 	[self applyOtherOptionsOn:viewController];
52
 	
54
 	
53
 	[viewController optionsUpdated];
55
 	[viewController optionsUpdated];
63
 		viewController.view.backgroundColor = screenColor;
65
 		viewController.view.backgroundColor = screenColor;
64
 	}
66
 	}
65
 	
67
 	
66
-	if (self.statusBarBlur) {
67
-		UIView* curBlurView = [viewController.view viewWithTag:BLUR_STATUS_TAG];
68
-		if ([self.statusBarBlur boolValue]) {
69
-			if (!curBlurView) {
70
-				UIVisualEffectView *blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
71
-				blur.frame = [[UIApplication sharedApplication] statusBarFrame];
72
-				blur.tag = BLUR_STATUS_TAG;
73
-				[viewController.view insertSubview:blur atIndex:0];
74
-			}
75
-		} else {
76
-			if (curBlurView) {
77
-				[curBlurView removeFromSuperview];
78
-			}
79
-		}
80
-	}
81
-	
82
 	if (self.backgroundImage) {
68
 	if (self.backgroundImage) {
83
 		UIImageView* backgroundImageView = (viewController.view.subviews.count > 0) ? viewController.view.subviews[0] : nil;
69
 		UIImageView* backgroundImageView = (viewController.view.subviews.count > 0) ? viewController.view.subviews[0] : nil;
84
 		if (![backgroundImageView isKindOfClass:[UIImageView class]]) {
70
 		if (![backgroundImageView isKindOfClass:[UIImageView class]]) {
102
 		backgroundImageView.image = [self.rootBackgroundImage isKindOfClass:[UIImage class]] ? (UIImage*)self.rootBackgroundImage : [RCTConvert UIImage:self.rootBackgroundImage];
88
 		backgroundImageView.image = [self.rootBackgroundImage isKindOfClass:[UIImage class]] ? (UIImage*)self.rootBackgroundImage : [RCTConvert UIImage:self.rootBackgroundImage];
103
 		[backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
89
 		[backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
104
 	}
90
 	}
105
-	
106
-	if (self.statusBarStyle) {
107
-		[viewController setNeedsStatusBarAppearanceUpdate];
108
-	}
109
     
91
     
110
     [self applyModalOptions:viewController];
92
     [self applyModalOptions:viewController];
111
 }
93
 }

+ 3
- 3
lib/ios/RNNRootViewController.m View File

158
 }
158
 }
159
 
159
 
160
 - (BOOL)prefersStatusBarHidden {
160
 - (BOOL)prefersStatusBarHidden {
161
-	if ([self.options.statusBarHidden boolValue]) {
161
+	if ([self.options.statusBar.hidden boolValue]) {
162
 		return YES;
162
 		return YES;
163
-	} else if ([self.options.statusBarHideWithTopBar boolValue]) {
163
+	} else if ([self.options.statusBar.hideWithTopBar boolValue]) {
164
 		return self.navigationController.isNavigationBarHidden;
164
 		return self.navigationController.isNavigationBarHidden;
165
 	}
165
 	}
166
 	return NO;
166
 	return NO;
167
 }
167
 }
168
 
168
 
169
 - (UIStatusBarStyle)preferredStatusBarStyle {
169
 - (UIStatusBarStyle)preferredStatusBarStyle {
170
-	if (self.options.statusBarStyle && [self.options.statusBarStyle isEqualToString:@"light"]) {
170
+	if (self.options.statusBar.style && [self.options.statusBar.style isEqualToString:@"light"]) {
171
 		return UIStatusBarStyleLightContent;
171
 		return UIStatusBarStyleLightContent;
172
 	} else {
172
 	} else {
173
 		return UIStatusBarStyleDefault;
173
 		return UIStatusBarStyleDefault;

+ 12
- 0
lib/ios/RNNStatusBarOptions.h View File

1
+#import "RNNOptions.h"
2
+
3
+extern const NSInteger BLUR_STATUS_TAG;
4
+
5
+@interface RNNStatusBarOptions : RNNOptions
6
+
7
+@property (nonatomic, strong) NSNumber* blur;
8
+@property (nonatomic, strong) NSNumber* hideWithTopBar;
9
+@property (nonatomic, strong) NSString* style;
10
+@property (nonatomic, strong) NSNumber* hidden;
11
+
12
+@end

+ 27
- 0
lib/ios/RNNStatusBarOptions.m View File

1
+#import "RNNStatusBarOptions.h"
2
+
3
+@implementation RNNStatusBarOptions
4
+
5
+- (void)applyOn:(UIViewController *)viewController {
6
+	if (self.blur) {
7
+		UIView* curBlurView = [viewController.view viewWithTag:BLUR_STATUS_TAG];
8
+		if ([self.blur boolValue]) {
9
+			if (!curBlurView) {
10
+				UIVisualEffectView *blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
11
+				blur.frame = [[UIApplication sharedApplication] statusBarFrame];
12
+				blur.tag = BLUR_STATUS_TAG;
13
+				[viewController.view insertSubview:blur atIndex:0];
14
+			}
15
+		} else {
16
+			if (curBlurView) {
17
+				[curBlurView removeFromSuperview];
18
+			}
19
+		}
20
+	}
21
+	
22
+	if (self.style) {
23
+		[viewController setNeedsStatusBarAppearanceUpdate];
24
+	}
25
+}
26
+
27
+@end

+ 4
- 2
playground/src/screens/OptionsScreen.js View File

16
 class OptionsScreen extends Component {
16
 class OptionsScreen extends Component {
17
   static get options() {
17
   static get options() {
18
     return {
18
     return {
19
-      statusBarBackgroundColor: '#EDEDED',
20
-      statusBarStyle: 'dark',
19
+      statusBar: {
20
+        style: 'dark',
21
+        backgroundColor: '#EDEDED'
22
+      },
21
       topBar: {
23
       topBar: {
22
         title: {
24
         title: {
23
           text: 'Static Title',
25
           text: 'Static Title',

+ 1
- 1
playground/src/screens/TopBarBackground.js View File

44
   container: {
44
   container: {
45
     flex: 1,
45
     flex: 1,
46
     flexDirection: 'row',
46
     flexDirection: 'row',
47
-    backgroundColor: '#e0e0e0',
47
+    backgroundColor: '#EDEDED',
48
     flexWrap: 'wrap'
48
     flexWrap: 'wrap'
49
   },
49
   },
50
   dot: {
50
   dot: {