Ver código fonte

Layout background color (#5946)

* Apply layout.backgroundColor on parent view controllers

* Add layout.componentBackgroundColor

* Remove drawBehind deprecation
Yogev Ben David 4 anos atrás
pai
commit
950642d48b
Nenhuma conta vinculada ao e-mail do autor do commit

+ 0
- 2
lib/ios/DeprecationOptions.h Ver arquivo

@@ -2,6 +2,4 @@
2 2
 
3 3
 @interface DeprecationOptions : RNNOptions
4 4
 
5
-@property (nonatomic, strong) Bool* deprecateDrawBehind;
6
-
7 5
 @end

+ 0
- 1
lib/ios/DeprecationOptions.m Ver arquivo

@@ -4,7 +4,6 @@
4 4
 
5 5
 - (instancetype)initWithDict:(NSDictionary *)dict {
6 6
     self = [super init];
7
-    self.deprecateDrawBehind = [BoolParser parse:dict key:@"deprecateDrawBehind"];
8 7
     return self;
9 8
 }
10 9
 

+ 5
- 0
lib/ios/RNNBottomTabsPresenter.m Ver arquivo

@@ -25,6 +25,7 @@
25 25
     [bottomTabs setTabBarHideShadow:[withDefault.bottomTabs.hideShadow getWithDefaultValue:NO]];
26 26
     [bottomTabs setTabBarStyle:[RCTConvert UIBarStyle:[withDefault.bottomTabs.barStyle getWithDefaultValue:@"default"]]];
27 27
     [bottomTabs setTabBarVisible:[withDefault.bottomTabs.visible getWithDefaultValue:YES] animated:[withDefault.bottomTabs.animate getWithDefaultValue:NO]];
28
+    [bottomTabs.view setBackgroundColor:[withDefault.layout.backgroundColor getWithDefaultValue:nil]];
28 29
 }
29 30
 
30 31
 - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)currentOptions {
@@ -68,6 +69,10 @@
68 69
             [bottomTabs setTabBarVisible:options.bottomTabs.visible.get animated:NO];
69 70
         }
70 71
     }
72
+    
73
+    if (options.layout.backgroundColor.hasValue) {
74
+        [bottomTabs.view setBackgroundColor:options.layout.backgroundColor.get];
75
+    }
71 76
 }
72 77
 
73 78
 - (void)viewDidLayoutSubviews {

+ 15
- 15
lib/ios/RNNComponentPresenter.m Ver arquivo

@@ -59,11 +59,13 @@
59 59
 	[viewController setStatusBarStyle:[withDefault.statusBar.style getWithDefaultValue:@"default"] animated:[withDefault.statusBar.animate getWithDefaultValue:YES]];
60 60
 	[viewController setBackButtonVisible:[withDefault.topBar.backButton.visible getWithDefaultValue:YES]];
61 61
 	[viewController setInterceptTouchOutside:[withDefault.overlay.interceptTouchOutside getWithDefaultValue:YES]];
62
-
63
-	if (withDefault.layout.backgroundColor.hasValue) {
64
-		[viewController setBackgroundColor:withDefault.layout.backgroundColor.get];
65
-	}
66
-
62
+    
63
+    if (@available(iOS 13.0, *)) {
64
+        [viewController setBackgroundColor:[withDefault.layout.componentBackgroundColor getWithDefaultValue:UIColor.systemBackgroundColor]];
65
+    } else {
66
+        [viewController setBackgroundColor:[withDefault.layout.componentBackgroundColor getWithDefaultValue:viewController.view.backgroundColor]];
67
+    }
68
+    
67 69
 	if (withDefault.topBar.searchBar.hasValue) {
68 70
 		BOOL hideNavBarOnFocusSearchBar = YES;
69 71
 		if (withDefault.topBar.hideNavBarOnFocusSearchBar.hasValue) {
@@ -81,10 +83,8 @@
81 83
 	UIViewController* viewController = self.boundViewController;
82 84
 	RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
83 85
     
84
-	if (![withDefault.deprecations.deprecateDrawBehind getWithDefaultValue:NO]) {
85
-		[viewController setDrawBehindTopBar:[withDefault.topBar.drawBehind getWithDefaultValue:NO]];
86
-		[viewController setDrawBehindTabBar:[withDefault.bottomTabs.drawBehind getWithDefaultValue:NO] || ![withDefault.bottomTabs.visible getWithDefaultValue:YES]];
87
-	}
86
+	[viewController setDrawBehindTopBar:[withDefault.topBar.drawBehind getWithDefaultValue:NO]];
87
+    [viewController setDrawBehindTabBar:[withDefault.bottomTabs.drawBehind getWithDefaultValue:NO] || ![withDefault.bottomTabs.visible getWithDefaultValue:YES]];
88 88
     
89 89
 	if ((withDefault.topBar.leftButtons || withDefault.topBar.rightButtons)) {
90 90
 		[_navigationButtons applyLeftButtons:withDefault.topBar.leftButtons rightButtons:withDefault.topBar.rightButtons defaultLeftButtonStyle:withDefault.topBar.leftButtonStyle defaultRightButtonStyle:withDefault.topBar.rightButtonStyle];
@@ -116,7 +116,7 @@
116 116
 		[viewController setSearchBarWithPlaceholder:[options.topBar.searchBarPlaceholder getWithDefaultValue:@""] hideNavBarOnFocusSearchBar:hideNavBarOnFocusSearchBar];
117 117
 	}
118 118
 
119
-	if (options.topBar.drawBehind.hasValue && ![withDefault.deprecations.deprecateDrawBehind getWithDefaultValue:NO]) {
119
+	if (options.topBar.drawBehind.hasValue) {
120 120
 		[viewController setDrawBehindTopBar:options.topBar.drawBehind.get];
121 121
   }
122 122
 
@@ -127,15 +127,15 @@
127 127
 	if (options.topBar.largeTitle.visible.hasValue) {
128 128
 		[viewController setTopBarPrefersLargeTitle:options.topBar.largeTitle.visible.get];
129 129
 	}
130
-
130
+    
131
+    if (options.layout.componentBackgroundColor.hasValue) {
132
+        [viewController setBackgroundColor:options.layout.componentBackgroundColor.get];
133
+    }
134
+    
131 135
 	if (options.bottomTab.badgeColor.hasValue) {
132 136
 		[viewController setTabBarItemBadgeColor:options.bottomTab.badgeColor.get];
133 137
 	}
134 138
 	
135
-	if (options.layout.backgroundColor.hasValue) {
136
-		[viewController setBackgroundColor:options.layout.backgroundColor.get];
137
-	}
138
-	
139 139
 	if (options.bottomTab.visible.hasValue) {
140 140
 		[viewController.tabBarController setCurrentTabIndex:[viewController.tabBarController.viewControllers indexOfObject:viewController]];
141 141
 	}

+ 1
- 0
lib/ios/RNNLayoutOptions.h Ver arquivo

@@ -3,6 +3,7 @@
3 3
 @interface RNNLayoutOptions : RNNOptions
4 4
 
5 5
 @property (nonatomic, strong) Color* backgroundColor;
6
+@property (nonatomic, strong) Color* componentBackgroundColor;
6 7
 @property (nonatomic, strong) Text* direction;
7 8
 @property (nonatomic, strong) id orientation;
8 9
 

+ 1
- 0
lib/ios/RNNLayoutOptions.m Ver arquivo

@@ -8,6 +8,7 @@
8 8
 	self = [super init];
9 9
 	
10 10
 	self.backgroundColor = [ColorParser parse:dict key:@"backgroundColor"];
11
+    self.componentBackgroundColor = [ColorParser parse:dict key:@"componentBackgroundColor"];
11 12
 	self.direction = [TextParser parse:dict key:@"direction"];
12 13
 	self.orientation = dict[@"orientation"];
13 14
 

+ 6
- 0
lib/ios/RNNSideMenuPresenter.m Ver arquivo

@@ -41,6 +41,8 @@
41 41
 		[sideMenu side:MMDrawerSideRight visible:withDefault.sideMenu.right.visible.get];
42 42
 		[withDefault.sideMenu.right.visible consume];
43 43
 	}
44
+    
45
+    [sideMenu.view setBackgroundColor:[withDefault.layout.backgroundColor getWithDefaultValue:nil]];
44 46
 }
45 47
 
46 48
 - (void)applyOptionsOnInit:(RNNNavigationOptions *)initialOptions {
@@ -108,6 +110,10 @@
108 110
 	if (options.sideMenu.animationType.hasValue) {
109 111
 		[sideMenu setAnimationType:options.sideMenu.animationType.get];
110 112
 	}
113
+    
114
+    if (options.layout.backgroundColor.hasValue) {
115
+        [sideMenu.view setBackgroundColor:options.layout.backgroundColor.get];
116
+    }
111 117
 }
112 118
 
113 119
 @end

+ 6
- 0
lib/ios/RNNStackPresenter.m Ver arquivo

@@ -65,6 +65,8 @@
65 65
     [stack setNavigationBarLargeTitleVisible:[withDefault.topBar.largeTitle.visible getWithDefaultValue:NO]];
66 66
     [stack setNavigationBarClipsToBounds:[withDefault.topBar.background.clipToBounds getWithDefaultValue:NO]];
67 67
     [stack setBackButtonColor:[withDefault.topBar.backButton.color getWithDefaultValue:nil]];
68
+	
69
+	[stack.view setBackgroundColor:[withDefault.layout.backgroundColor getWithDefaultValue:nil]];
68 70
 }
69 71
 
70 72
 - (void)applyOptionsOnViewDidLayoutSubviews:(RNNNavigationOptions *)options {
@@ -128,6 +130,10 @@
128 130
     if (options.topBar.background.component.name.hasValue) {
129 131
         [self setCustomNavigationComponentBackground:options perform:nil];
130 132
     }
133
+	
134
+	if (options.layout.backgroundColor.hasValue) {
135
+		[stack.view setBackgroundColor:options.layout.backgroundColor.get];
136
+	}
131 137
     
132 138
     RNNNavigationOptions * withDefault = (RNNNavigationOptions *) [[options mergeInOptions:resolvedOptions] withDefault:[self defaultOptions]];
133 139
     [_topBarPresenter mergeOptions:options.topBar withDefault:withDefault.topBar];

+ 2
- 18
lib/src/commands/Deprecations.ts Ver arquivo

@@ -1,26 +1,10 @@
1
-import isEqual from 'lodash/isEqual';
2
-import once from 'lodash/once';
3
-import { Platform } from 'react-native';
4 1
 
5 2
 export class Deprecations {
6
-  private deprecateDrawBehind = once((parentOptions: object) => {
7
-    this.warnDeprecatedOption('drawBehind', 'Please use SafeAreaView, or ScrollView and set drawBehind true in default options. For more information see https://github.com/wix/react-native-navigation/issues/5913', parentOptions);
8
-  });
3
+  public onProcessOptions(_key: string, _parentOptions: Record<string, any>) {
9 4
 
10
-  public onProcessOptions(key: string, parentOptions: Record<string, any>) {
11
-    if (isEqual(key, 'drawBehind') && Platform.OS === 'ios') {
12
-      this.deprecateDrawBehind(parentOptions);
13
-    }
14 5
   }
15 6
 
16
-  public onProcessDefaultOptions(key: string, parentOptions: Record<string, any>) {
17
-    if (isEqual(key, 'drawBehind') && Platform.OS === 'ios' && parentOptions[key] === false) {
18
-      this.deprecateDrawBehind(parentOptions);
19
-    }
20
-  }
7
+  public onProcessDefaultOptions(_key: string, _parentOptions: Record<string, any>) {
21 8
 
22
-  private warnDeprecatedOption(key: string, message: string, parentOptions: object) {
23
-    // tslint:disable-next-line:no-console
24
-    console.warn(`${key} is deprecated. ${message}`, parentOptions);
25 9
   }
26 10
 }

+ 1
- 1
playground/ios/NavigationIOS12Tests/RNNRootViewControllerTest.m Ver arquivo

@@ -132,7 +132,7 @@
132 132
 
133 133
 -(void)testbackgroundColor_validColor{
134 134
 	UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
135
-	self.options.layout.backgroundColor = [[Color alloc] initWithValue:inputColor];
135
+	self.options.layout.componentBackgroundColor = [[Color alloc] initWithValue:inputColor];
136 136
 	[self.uut viewWillAppear:false];
137 137
 	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
138 138
 	XCTAssertTrue([self.uut.view.backgroundColor isEqual:expectedColor]);

+ 7
- 2
playground/ios/NavigationTests/RNNRootViewControllerTest.m Ver arquivo

@@ -130,14 +130,19 @@
130 130
 	XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
131 131
 }
132 132
 
133
-- (void)testbackgroundColor_validColor{
133
+- (void)testBackgroundColor_validColor {
134 134
 	UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
135
-	self.options.layout.backgroundColor = [[Color alloc] initWithValue:inputColor];
135
+	self.options.layout.componentBackgroundColor = [[Color alloc] initWithValue:inputColor];
136 136
 	[self.uut viewWillAppear:false];
137 137
 	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
138 138
 	XCTAssertTrue([self.uut.view.backgroundColor isEqual:expectedColor]);
139 139
 }
140 140
 
141
+- (void)testDefaultBackgroundColor {
142
+	[self.uut viewWillAppear:false];
143
+	XCTAssertTrue([self.uut.view.backgroundColor isEqual:UIColor.systemBackgroundColor]);
144
+}
145
+
141 146
 - (void)testTopBarTextFontFamily_validFont{
142 147
 	NSString* inputFont = @"HelveticaNeue";
143 148
 	__unused RNNStackController* nav = [self createNavigationController];

+ 35
- 27
playground/ios/NavigationTests/RNNSideMenuPresenterTest.m Ver arquivo

@@ -7,7 +7,7 @@
7 7
 
8 8
 @property (nonatomic, strong) RNNSideMenuPresenter *uut;
9 9
 @property (nonatomic, strong) RNNNavigationOptions *options;
10
-@property (nonatomic, strong) id bindedViewController;
10
+@property (nonatomic, strong) id boundViewController;
11 11
 
12 12
 @end
13 13
 
@@ -16,25 +16,25 @@
16 16
 - (void)setUp {
17 17
     [super setUp];
18 18
 	self.uut = [[RNNSideMenuPresenter alloc] init];
19
-	self.bindedViewController = [OCMockObject partialMockForObject:[RNNSideMenuController new]];
20
-    [self.uut bindViewController:self.bindedViewController];
19
+	self.boundViewController = [OCMockObject partialMockForObject:[RNNSideMenuController new]];
20
+    [self.uut bindViewController:self.boundViewController];
21 21
 	self.options = [[RNNNavigationOptions alloc] initEmptyOptions];
22 22
 }
23 23
 
24 24
 - (void)testApplyOptionsShouldSetDefaultValues {
25
-	[[self.bindedViewController expect] side:MMDrawerSideLeft enabled:YES];
26
-	[[self.bindedViewController expect] side:MMDrawerSideRight enabled:YES];
27
-	[[self.bindedViewController expect] setShouldStretchLeftDrawer:YES];
28
-	[[self.bindedViewController expect] setShouldStretchRightDrawer:YES];
29
-	[[self.bindedViewController expect] setAnimationVelocityLeft:840.0f];
30
-	[[self.bindedViewController expect] setAnimationVelocityRight:840.0f];
31
-	[[self.bindedViewController reject] side:MMDrawerSideLeft width:0];
32
-	[[self.bindedViewController reject] side:MMDrawerSideRight width:0];
33
-  	[[self.bindedViewController expect] setAnimationType:nil];
25
+	[[self.boundViewController expect] side:MMDrawerSideLeft enabled:YES];
26
+	[[self.boundViewController expect] side:MMDrawerSideRight enabled:YES];
27
+	[[self.boundViewController expect] setShouldStretchLeftDrawer:YES];
28
+	[[self.boundViewController expect] setShouldStretchRightDrawer:YES];
29
+	[[self.boundViewController expect] setAnimationVelocityLeft:840.0f];
30
+	[[self.boundViewController expect] setAnimationVelocityRight:840.0f];
31
+	[[self.boundViewController reject] side:MMDrawerSideLeft width:0];
32
+	[[self.boundViewController reject] side:MMDrawerSideRight width:0];
33
+  	[[self.boundViewController expect] setAnimationType:nil];
34 34
     
35 35
 	[self.uut applyOptions:self.options];
36 36
 
37
-	[self.bindedViewController verify];
37
+	[self.boundViewController verify];
38 38
 }
39 39
 
40 40
 - (void)testApplyOptionsShouldSetInitialValues {
@@ -45,41 +45,49 @@
45 45
 	self.options.sideMenu.right.animationVelocity = [[Double alloc] initWithValue:@(100.0f)];
46 46
 	self.options.sideMenu.left.animationVelocity = [[Double alloc] initWithValue:@(100.0f)];
47 47
 	
48
-	[[self.bindedViewController expect] side:MMDrawerSideLeft enabled:NO];
49
-	[[self.bindedViewController expect] side:MMDrawerSideRight enabled:NO];
50
-	[[self.bindedViewController expect] setShouldStretchLeftDrawer:NO];
51
-	[[self.bindedViewController expect] setShouldStretchRightDrawer:NO];
52
-	[[self.bindedViewController expect] setAnimationVelocityLeft:100.0f];
53
-	[[self.bindedViewController expect] setAnimationVelocityRight:100.0f];
48
+	[[self.boundViewController expect] side:MMDrawerSideLeft enabled:NO];
49
+	[[self.boundViewController expect] side:MMDrawerSideRight enabled:NO];
50
+	[[self.boundViewController expect] setShouldStretchLeftDrawer:NO];
51
+	[[self.boundViewController expect] setShouldStretchRightDrawer:NO];
52
+	[[self.boundViewController expect] setAnimationVelocityLeft:100.0f];
53
+	[[self.boundViewController expect] setAnimationVelocityRight:100.0f];
54 54
 	
55 55
 	[self.uut applyOptions:self.options];
56 56
 	
57
-	[self.bindedViewController verify];
57
+	[self.boundViewController verify];
58 58
 }
59 59
 
60 60
 - (void)testApplyOptionsOnInitShouldSetWidthOptions {
61 61
 	self.options.sideMenu.right.width = [[Double alloc] initWithValue:@(100.0f)];
62 62
 	self.options.sideMenu.left.width = [[Double alloc] initWithValue:@(100.0f)];
63 63
 
64
-	[[self.bindedViewController expect] side:MMDrawerSideLeft width:100.0f];
65
-	[[self.bindedViewController expect] side:MMDrawerSideRight width:100.0f];
64
+	[[self.boundViewController expect] side:MMDrawerSideLeft width:100.0f];
65
+	[[self.boundViewController expect] side:MMDrawerSideRight width:100.0f];
66 66
 	
67 67
 	[self.uut applyOptionsOnInit:self.options];
68 68
 	
69
-	[self.bindedViewController verify];
69
+	[self.boundViewController verify];
70 70
 }
71 71
 
72 72
 - (void)testApplyOptionsOnInitShouldSetDefaultDrawerGestureMode {
73
-	[[self.bindedViewController expect] setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
73
+	[[self.boundViewController expect] setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
74 74
 	[self.uut applyOptionsOnInit:self.options];
75
-	[self.bindedViewController verify];
75
+	[self.boundViewController verify];
76 76
 }
77 77
 
78 78
 - (void)testApplyOptionsOnInitShouldSetBezelDrawerGestureMode {
79 79
 	self.options.sideMenu.openGestureMode = [[SideMenuOpenMode alloc] initWithValue:@(MMOpenDrawerGestureModeNone)];
80
-	[[self.bindedViewController expect] setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeNone];
80
+	[[self.boundViewController expect] setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeNone];
81 81
 	[self.uut applyOptionsOnInit:self.options];
82
-	[self.bindedViewController verify];
82
+	[self.boundViewController verify];
83
+}
84
+
85
+- (void)testBackgroundColor_validColor {
86
+	UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
87
+	self.options.layout.backgroundColor = [[Color alloc] initWithValue:inputColor];
88
+	[self.uut applyOptions:self.options];
89
+	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
90
+	XCTAssertTrue([((UIViewController *)self.boundViewController).view.backgroundColor isEqual:expectedColor]);
83 91
 }
84 92
 
85 93
 @end

+ 8
- 0
playground/ios/NavigationTests/RNNStackPresenterTest.m Ver arquivo

@@ -106,4 +106,12 @@
106 106
 	XCTAssertTrue([self.boundViewController.navigationBar.standardAppearance.backIndicatorImage isEqual:image]);
107 107
 }
108 108
 
109
+- (void)testBackgroundColor_validColor {
110
+	UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
111
+	self.options.layout.backgroundColor = [[Color alloc] initWithValue:inputColor];
112
+	[self.uut applyOptions:self.options];
113
+	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
114
+	XCTAssertTrue([self.boundViewController.view.backgroundColor isEqual:expectedColor]);
115
+}
116
+
109 117
 @end

+ 8
- 0
playground/ios/NavigationTests/RNNTabBarPresenterTest.m Ver arquivo

@@ -92,4 +92,12 @@
92 92
     [uut verify];
93 93
 }
94 94
 
95
+- (void)testBackgroundColor_validColor {
96
+	UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
97
+	self.options.layout.backgroundColor = [[Color alloc] initWithValue:inputColor];
98
+	[self.uut applyOptions:self.options];
99
+	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
100
+	XCTAssertTrue([((UIViewController *)self.boundViewController).view.backgroundColor isEqual:expectedColor]);
101
+}
102
+
95 103
 @end