Browse Source

Fix topBar.background.color for older iOS versions (#5712)

Yogev Ben David 4 years ago
parent
commit
7cf208353f
No account linked to committer's email address

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

14
 #import "RNNModalOptions.h"
14
 #import "RNNModalOptions.h"
15
 
15
 
16
 extern const NSInteger BLUR_TOPBAR_TAG;
16
 extern const NSInteger BLUR_TOPBAR_TAG;
17
-extern const NSInteger TOP_BAR_TRANSPARENT_TAG;
18
 
17
 
19
 @interface RNNNavigationOptions : RNNOptions
18
 @interface RNNNavigationOptions : RNNOptions
20
 
19
 

+ 1
- 16
lib/ios/UINavigationBar+utils.m View File

1
 #import "UINavigationBar+utils.h"
1
 #import "UINavigationBar+utils.h"
2
 
2
 
3
-const NSInteger TOP_BAR_TRANSPARENT_TAG = 78264803;
4
 
3
 
5
 @implementation UINavigationBar (utils)
4
 @implementation UINavigationBar (utils)
6
 
5
 
34
         [self getNavigaitonBarScrollEdgeAppearance].backgroundColor = color;
33
         [self getNavigaitonBarScrollEdgeAppearance].backgroundColor = color;
35
     } else {
34
     } else {
36
         [super setBackgroundColor:color];
35
         [super setBackgroundColor:color];
37
-        [self removeTransparentView];
36
+        self.barTintColor = color;
38
     }
37
     }
39
 }
38
 }
40
 
39
 
49
         [self getNavigaitonBarScrollEdgeAppearance].backgroundEffect = nil;
48
         [self getNavigaitonBarScrollEdgeAppearance].backgroundEffect = nil;
50
         
49
         
51
     } else {
50
     } else {
52
-        if (![self viewWithTag:TOP_BAR_TRANSPARENT_TAG]){
53
-            UIView *transparentView = [[UIView alloc] initWithFrame:CGRectZero];
54
-            transparentView.backgroundColor = [UIColor clearColor];
55
-            transparentView.tag = TOP_BAR_TRANSPARENT_TAG;
56
-            [self insertSubview:transparentView atIndex:0];
57
-        }
58
-        
59
         [self setBackgroundColor:[UIColor clearColor]];
51
         [self setBackgroundColor:[UIColor clearColor]];
60
         self.shadowImage = [UIImage new];
52
         self.shadowImage = [UIImage new];
61
         [self setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
53
         [self setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
73
     }
65
     }
74
 }
66
 }
75
 
67
 
76
-- (void)removeTransparentView {
77
-    UIView *transparentView = [self viewWithTag:TOP_BAR_TRANSPARENT_TAG];
78
-    if (transparentView){
79
-        [transparentView removeFromSuperview];
80
-    }
81
-}
82
-
83
 - (void)configureWithTransparentBackground {
68
 - (void)configureWithTransparentBackground {
84
     if (@available(iOS 13.0, *)) {
69
     if (@available(iOS 13.0, *)) {
85
         [[self getNavigaitonBarStandardAppearance] configureWithTransparentBackground];
70
         [[self getNavigaitonBarStandardAppearance] configureWithTransparentBackground];

+ 0
- 1
playground/ios/NavigationTests/RNNNavigationControllerTest.m View File

178
 	[self.uut setTopBarBackgroundColor:redColor];
178
 	[self.uut setTopBarBackgroundColor:redColor];
179
 	[self.uut setTopBarBackgroundColor:nil];
179
 	[self.uut setTopBarBackgroundColor:nil];
180
 	
180
 	
181
-	XCTAssertNil([self.uut.navigationBar viewWithTag:TOP_BAR_TRANSPARENT_TAG]);
182
 	XCTAssertNil(self.uut.navigationBar.barTintColor);
181
 	XCTAssertNil(self.uut.navigationBar.barTintColor);
183
 	XCTAssertNil(self.uut.navigationBar.standardAppearance.backgroundColor);
182
 	XCTAssertNil(self.uut.navigationBar.standardAppearance.backgroundColor);
184
 	XCTAssertNil(self.uut.navigationBar.compactAppearance.backgroundColor);
183
 	XCTAssertNil(self.uut.navigationBar.compactAppearance.backgroundColor);

+ 0
- 9
playground/ios/NavigationTests/RNNRootViewControllerTest.m View File

177
 
177
 
178
 }
178
 }
179
 
179
 
180
--(void)testTopBarTransparent_BOOL_false {
181
-	UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
182
-	__unused RNNStackController* nav = [self createNavigationController];
183
-	self.options.topBar.background.color = [[Color alloc] initWithValue:inputColor];
184
-	[self.uut viewWillAppear:false];
185
-	UIView* transparentView = [self.uut.navigationController.navigationBar viewWithTag:TOP_BAR_TRANSPARENT_TAG];
186
-	XCTAssertFalse(transparentView);
187
-}
188
-
189
 -(void)testTopBarLargeTitle_default {
180
 -(void)testTopBarLargeTitle_default {
190
 	[self.uut viewWillAppear:false];
181
 	[self.uut viewWillAppear:false];
191
 
182