Browse Source

topBarBlur for ios (#1760)

Graham Chance 7 years ago
parent
commit
d15117e644

+ 1
- 1
README.md View File

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)       | @gtchance|
86
 | statusBarBlur         |  ✅     |    ✅     |      [Contribute](CONTRIBUTING.md)       | @gtchance|
87
-| topBarBlur            | ✅      |    [Contribute](CONTRIBUTING.md)     |      [Contribute](CONTRIBUTING.md)       |
87
+| topBarBlur            | ✅      |    ✅     |      [Contribute](CONTRIBUTING.md)       | @gtchance|
88
 | tabBarHidden  |   ✅  |   ✅     |    [Contribute](CONTRIBUTING.md)        | @gtchance|
88
 | tabBarHidden  |   ✅  |   ✅     |    [Contribute](CONTRIBUTING.md)        | @gtchance|
89
 | statusBarTextColorScheme |  ✅   |   in development      |      / iOS specific    |
89
 | statusBarTextColorScheme |  ✅   |   in development      |      / iOS specific    |
90
 | statusBarTextColorSchemeSingleScreen|  ✅   |     in development    |     / iOS specific      |
90
 | statusBarTextColorSchemeSingleScreen|  ✅   |     in development    |     / iOS specific      |

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

2
 #import <UIKit/UIKit.h>
2
 #import <UIKit/UIKit.h>
3
 
3
 
4
 extern const NSInteger BLUR_STATUS_TAG;
4
 extern const NSInteger BLUR_STATUS_TAG;
5
+extern const NSInteger BLUR_TOPBAR_TAG;
5
 
6
 
6
 @interface RNNNavigationOptions : NSObject
7
 @interface RNNNavigationOptions : NSObject
7
 
8
 
23
 @property (nonatomic, strong) NSNumber* statusBarBlur;
24
 @property (nonatomic, strong) NSNumber* statusBarBlur;
24
 @property (nonatomic, strong) NSNumber* statusBarHideWithTopBar;
25
 @property (nonatomic, strong) NSNumber* statusBarHideWithTopBar;
25
 @property (nonatomic, strong) NSNumber* tabBarHidden;
26
 @property (nonatomic, strong) NSNumber* tabBarHidden;
27
+@property (nonatomic, strong) NSNumber* topBarBlur;
26
 
28
 
27
 -(instancetype)init;
29
 -(instancetype)init;
28
 -(instancetype)initWithDict:(NSDictionary *)navigationOptions;
30
 -(instancetype)initWithDict:(NSDictionary *)navigationOptions;

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

2
 #import <React/RCTConvert.h>
2
 #import <React/RCTConvert.h>
3
 
3
 
4
 const NSInteger BLUR_STATUS_TAG = 78264801;
4
 const NSInteger BLUR_STATUS_TAG = 78264801;
5
+const NSInteger BLUR_TOPBAR_TAG = 78264802;
5
 
6
 
6
 @implementation RNNNavigationOptions
7
 @implementation RNNNavigationOptions
7
 
8
 
27
 	self.rightButtons = [navigationOptions objectForKey:@"rightButtons"];
28
 	self.rightButtons = [navigationOptions objectForKey:@"rightButtons"];
28
 	self.topBarNoBorder = [navigationOptions objectForKey:@"topBarNoBorder"];
29
 	self.topBarNoBorder = [navigationOptions objectForKey:@"topBarNoBorder"];
29
 	self.tabBarHidden = [navigationOptions objectForKey:@"tabBarHidden"];
30
 	self.tabBarHidden = [navigationOptions objectForKey:@"tabBarHidden"];
31
+	self.topBarBlur = [navigationOptions objectForKey:@"topBarBlur"];
30
 
32
 
31
 	return self;
33
 	return self;
32
 }
34
 }
137
 			}
139
 			}
138
 		}
140
 		}
139
 	}
141
 	}
140
-	
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
+
141
 }
167
 }
142
 
168
 
143
 @end
169
 @end

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

342
 	XCTAssertFalse([self.uut hidesBottomBarWhenPushed]);
342
 	XCTAssertFalse([self.uut hidesBottomBarWhenPushed]);
343
 }
343
 }
344
 
344
 
345
+-(void)testTopBarBlur_default {
346
+	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
347
+	[self.uut viewWillAppear:false];
348
+	XCTAssertNil([self.uut.navigationController.navigationBar viewWithTag:BLUR_TOPBAR_TAG]);
349
+}
350
+
351
+
352
+-(void)testTopBarBlur_false {
353
+	NSNumber* topBarBlurInput = @(0);
354
+	self.options.topBarBlur = topBarBlurInput;
355
+	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
356
+	[self.uut viewWillAppear:false];
357
+	XCTAssertNil([self.uut.navigationController.navigationBar viewWithTag:BLUR_TOPBAR_TAG]);
358
+}
359
+
360
+-(void)testTopBarBlur_true {
361
+	NSNumber* topBarBlurInput = @(1);
362
+	self.options.topBarBlur = topBarBlurInput;
363
+	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
364
+	[self.uut viewWillAppear:false];
365
+	XCTAssertNotNil([self.uut.navigationController.navigationBar viewWithTag:BLUR_TOPBAR_TAG]);
366
+}
367
+
345
 @end
368
 @end