Parcourir la source

V2 status bar blur ios (#1700)

* statusBarBlur for ios

* unit tests for ios statusBarBlur

* Update README.md
Graham Chance il y a 7 ans
Parent
révision
f3607da475

+ 2
- 2
README.md Voir le fichier

@@ -80,10 +80,10 @@ Note:  v1 properties with names beginning with 'navBar' are replaced in v2 with
80 80
 | topBarHideOnScroll    |  ✅     |  ✅    |     [Contribute](CONTRIBUTING.md)        |
81 81
 | topBarTranslucent     |  ✅     |   ✅     |     [Contribute](CONTRIBUTING.md)        |
82 82
 | topBarTransparent     | ✅      |   WIP @bogobogo     |     [Contribute](CONTRIBUTING.md)        |
83
-| topBarNoBorder        |  ✅     |    [Contribute](CONTRIBUTING.md)     |     [Contribute](CONTRIBUTING.md)        |
83
+| topBarNoBorder        |  ✅     |         |     [Contribute](CONTRIBUTING.md)        |
84 84
 | drawUnderTabBar       |  ✅     |    WIP @gran33     |      [Contribute](CONTRIBUTING.md)       |
85 85
 | drawUnderTopBar       |  ✅     |    WIP @gran33     |      [Contribute](CONTRIBUTING.md)       |
86
-| statusBarBlur         |  ✅     |    [Contribute](CONTRIBUTING.md)     |      [Contribute](CONTRIBUTING.md)       |
86
+| statusBarBlur         |  ✅     |         |      [Contribute](CONTRIBUTING.md)       |
87 87
 | topBarBlur            | ✅      |    [Contribute](CONTRIBUTING.md)     |      [Contribute](CONTRIBUTING.md)       |
88 88
 | tabBarHidden  |   ✅  |   [Contribute](CONTRIBUTING.md)     |    [Contribute](CONTRIBUTING.md)        |
89 89
 | statusBarTextColorScheme |  ✅   |   in development      |      / iOS specific    |

+ 3
- 1
lib/ios/RNNNavigationOptions.h Voir le fichier

@@ -1,6 +1,8 @@
1 1
 #import <Foundation/Foundation.h>
2 2
 #import <UIKit/UIKit.h>
3 3
 
4
+extern const NSInteger BLUR_STATUS_TAG;
5
+
4 6
 @interface RNNNavigationOptions : NSObject
5 7
 
6 8
 @property (nonatomic, strong) NSNumber* topBarBackgroundColor;
@@ -16,7 +18,7 @@
16 18
 @property (nonatomic, strong) NSString* tabBadge;
17 19
 @property (nonatomic, strong) NSNumber* topBarTextFontSize;
18 20
 @property (nonatomic, strong) NSNumber* topBarNoBorder;
19
-
21
+@property (nonatomic, strong) NSNumber* statusBarBlur;
20 22
 
21 23
 
22 24
 -(instancetype)init;

+ 18
- 1
lib/ios/RNNNavigationOptions.m Voir le fichier

@@ -1,6 +1,7 @@
1 1
 #import "RNNNavigationOptions.h"
2 2
 #import <React/RCTConvert.h>
3 3
 
4
+const NSInteger BLUR_STATUS_TAG = 78264801;
4 5
 
5 6
 @implementation RNNNavigationOptions
6 7
 
@@ -117,6 +118,22 @@
117 118
 			.shadowImage = nil;
118 119
 		}
119 120
 	}
120
-
121
+	
122
+	if (self.statusBarBlur) {
123
+		UIView* curBlurView = [viewController.view viewWithTag:BLUR_STATUS_TAG];
124
+		if ([self.statusBarBlur boolValue]) {
125
+			if (!curBlurView) {
126
+				UIVisualEffectView *blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
127
+				blur.frame = [[UIApplication sharedApplication] statusBarFrame];
128
+				blur.tag = BLUR_STATUS_TAG;
129
+				[viewController.view insertSubview:blur atIndex:0];
130
+			}
131
+		} else {
132
+			if (curBlurView) {
133
+				[curBlurView removeFromSuperview];
134
+			}
135
+		}
136
+	}
137
+	
121 138
 }
122 139
 @end

+ 17
- 0
lib/ios/ReactNativeNavigationTests/RNNRootViewControllerTest.m Voir le fichier

@@ -221,4 +221,21 @@
221 221
 	XCTAssertNil(self.uut.navigationController.navigationBar.shadowImage);
222 222
 }
223 223
 
224
+-(void)testStatusBarBlurOn {
225
+	NSNumber* statusBarBlurInput = @(1);
226
+	self.options.statusBarBlur = statusBarBlurInput;
227
+	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
228
+	[self.uut viewWillAppear:false];
229
+	XCTAssertNotNil([self.uut.view viewWithTag:BLUR_STATUS_TAG]);
230
+}
231
+
232
+-(void)testStatusBarBlurOff {
233
+	NSNumber* statusBarBlurInput = @(0);
234
+	self.options.statusBarBlur = statusBarBlurInput;
235
+	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
236
+	[self.uut viewWillAppear:false];
237
+	XCTAssertNil([self.uut.view viewWithTag:BLUR_STATUS_TAG]);
238
+}
239
+
240
+
224 241
 @end