Browse Source

V2 status bar blur ios (#1700)

* statusBarBlur for ios

* unit tests for ios statusBarBlur

* Update README.md
Graham Chance 7 years ago
parent
commit
f3607da475

+ 2
- 2
README.md View File

80
 | topBarHideOnScroll    |  ✅     |  ✅    |     [Contribute](CONTRIBUTING.md)        |
80
 | topBarHideOnScroll    |  ✅     |  ✅    |     [Contribute](CONTRIBUTING.md)        |
81
 | topBarTranslucent     |  ✅     |   ✅     |     [Contribute](CONTRIBUTING.md)        |
81
 | topBarTranslucent     |  ✅     |   ✅     |     [Contribute](CONTRIBUTING.md)        |
82
 | topBarTransparent     | ✅      |   WIP @bogobogo     |     [Contribute](CONTRIBUTING.md)        |
82
 | topBarTransparent     | ✅      |   WIP @bogobogo     |     [Contribute](CONTRIBUTING.md)        |
83
-| topBarNoBorder        |  ✅     |    [Contribute](CONTRIBUTING.md)     |     [Contribute](CONTRIBUTING.md)        |
83
+| topBarNoBorder        |  ✅     |         |     [Contribute](CONTRIBUTING.md)        |
84
 | drawUnderTabBar       |  ✅     |    WIP @gran33     |      [Contribute](CONTRIBUTING.md)       |
84
 | drawUnderTabBar       |  ✅     |    WIP @gran33     |      [Contribute](CONTRIBUTING.md)       |
85
 | drawUnderTopBar       |  ✅     |    WIP @gran33     |      [Contribute](CONTRIBUTING.md)       |
85
 | drawUnderTopBar       |  ✅     |    WIP @gran33     |      [Contribute](CONTRIBUTING.md)       |
86
-| statusBarBlur         |  ✅     |    [Contribute](CONTRIBUTING.md)     |      [Contribute](CONTRIBUTING.md)       |
86
+| statusBarBlur         |  ✅     |         |      [Contribute](CONTRIBUTING.md)       |
87
 | topBarBlur            | ✅      |    [Contribute](CONTRIBUTING.md)     |      [Contribute](CONTRIBUTING.md)       |
87
 | topBarBlur            | ✅      |    [Contribute](CONTRIBUTING.md)     |      [Contribute](CONTRIBUTING.md)       |
88
 | tabBarHidden  |   ✅  |   [Contribute](CONTRIBUTING.md)     |    [Contribute](CONTRIBUTING.md)        |
88
 | tabBarHidden  |   ✅  |   [Contribute](CONTRIBUTING.md)     |    [Contribute](CONTRIBUTING.md)        |
89
 | statusBarTextColorScheme |  ✅   |   in development      |      / iOS specific    |
89
 | statusBarTextColorScheme |  ✅   |   in development      |      / iOS specific    |

+ 3
- 1
lib/ios/RNNNavigationOptions.h View File

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

+ 18
- 1
lib/ios/RNNNavigationOptions.m View File

1
 #import "RNNNavigationOptions.h"
1
 #import "RNNNavigationOptions.h"
2
 #import <React/RCTConvert.h>
2
 #import <React/RCTConvert.h>
3
 
3
 
4
+const NSInteger BLUR_STATUS_TAG = 78264801;
4
 
5
 
5
 @implementation RNNNavigationOptions
6
 @implementation RNNNavigationOptions
6
 
7
 
117
 			.shadowImage = nil;
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
 @end
139
 @end

+ 17
- 0
lib/ios/ReactNativeNavigationTests/RNNRootViewControllerTest.m View File

221
 	XCTAssertNil(self.uut.navigationController.navigationBar.shadowImage);
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
 @end
241
 @end