Procházet zdrojové kódy

[Breaking] Status bar options (#3245)

* refactored status bar options iOS

* [Breaking] Pull StatusBar styles to separate object
Guy Carmeli před 6 roky
rodič
revize
98c6a6c205
No account linked to committer's email address

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/parse/Options.java Zobrazit soubor

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

+ 2
- 2
lib/android/app/src/main/java/com/reactnativenavigation/parse/StatusBarOptions.java Zobrazit soubor

@@ -39,8 +39,8 @@ public class StatusBarOptions {
39 39
         StatusBarOptions result = new StatusBarOptions();
40 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 45
         return result;
46 46
     }

+ 2
- 5
lib/ios/RNNNavigationOptions.h Zobrazit soubor

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

+ 2
- 20
lib/ios/RNNNavigationOptions.m Zobrazit soubor

@@ -48,6 +48,8 @@ RCT_ENUM_CONVERTER(UIModalTransitionStyle,
48 48
 	[self.bottomTab applyOn:viewController];
49 49
 	[self.sideMenu applyOn:viewController];
50 50
 	[self.overlay applyOn:viewController];
51
+	[self.statusBar applyOn:viewController];
52
+	
51 53
 	[self applyOtherOptionsOn:viewController];
52 54
 	
53 55
 	[viewController optionsUpdated];
@@ -63,22 +65,6 @@ RCT_ENUM_CONVERTER(UIModalTransitionStyle,
63 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 68
 	if (self.backgroundImage) {
83 69
 		UIImageView* backgroundImageView = (viewController.view.subviews.count > 0) ? viewController.view.subviews[0] : nil;
84 70
 		if (![backgroundImageView isKindOfClass:[UIImageView class]]) {
@@ -102,10 +88,6 @@ RCT_ENUM_CONVERTER(UIModalTransitionStyle,
102 88
 		backgroundImageView.image = [self.rootBackgroundImage isKindOfClass:[UIImage class]] ? (UIImage*)self.rootBackgroundImage : [RCTConvert UIImage:self.rootBackgroundImage];
103 89
 		[backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
104 90
 	}
105
-	
106
-	if (self.statusBarStyle) {
107
-		[viewController setNeedsStatusBarAppearanceUpdate];
108
-	}
109 91
     
110 92
     [self applyModalOptions:viewController];
111 93
 }

+ 3
- 3
lib/ios/RNNRootViewController.m Zobrazit soubor

@@ -158,16 +158,16 @@
158 158
 }
159 159
 
160 160
 - (BOOL)prefersStatusBarHidden {
161
-	if ([self.options.statusBarHidden boolValue]) {
161
+	if ([self.options.statusBar.hidden boolValue]) {
162 162
 		return YES;
163
-	} else if ([self.options.statusBarHideWithTopBar boolValue]) {
163
+	} else if ([self.options.statusBar.hideWithTopBar boolValue]) {
164 164
 		return self.navigationController.isNavigationBarHidden;
165 165
 	}
166 166
 	return NO;
167 167
 }
168 168
 
169 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 171
 		return UIStatusBarStyleLightContent;
172 172
 	} else {
173 173
 		return UIStatusBarStyleDefault;

+ 12
- 0
lib/ios/RNNStatusBarOptions.h Zobrazit soubor

@@ -0,0 +1,12 @@
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 Zobrazit soubor

@@ -0,0 +1,27 @@
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 Zobrazit soubor

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

+ 1
- 1
playground/src/screens/TopBarBackground.js Zobrazit soubor

@@ -44,7 +44,7 @@ const styles = StyleSheet.create({
44 44
   container: {
45 45
     flex: 1,
46 46
     flexDirection: 'row',
47
-    backgroundColor: '#e0e0e0',
47
+    backgroundColor: '#EDEDED',
48 48
     flexWrap: 'wrap'
49 49
   },
50 50
   dot: {