Quellcode durchsuchen

Allow TopBar -> Background -> Clip To Bounds option (#3913)

** For iOS only
Seth H Rogers vor 6 Jahren
Ursprung
Commit
a6413c132a

+ 1
- 0
docs/README.md Datei anzeigen

@@ -100,6 +100,7 @@ v2 is written in Test Driven Development. We have a test for every feature inclu
100 100
 | blur               |    ✅     |      [Contribute](/docs/WorkingLocally.md)       |
101 101
 | custom component          |✅     |✅|
102 102
 | background component          |✅     |✅|
103
+| background clipToBounds      |    ✅     |     /iOS Specific       |
103 104
 | subtitleColor            |   ✅      |✅|
104 105
 | subtitleFontFamily      |✅|✅|
105 106
 | largeTitle (iOS 11)      |    ✅     |     /iOS Specific       |

+ 14
- 0
docs/docs/options-migration.md Datei anzeigen

@@ -62,6 +62,20 @@ topBar: {
62 62
 }
63 63
 ```
64 64
 
65
+## navBarClipToBounds
66
+Restrict the navbar background color to the navbar, and do not flow behind the status bar.
67
+
68
+```js
69
+topBar: {
70
+  background: {
71
+    component: {
72
+      name: 'example.CustomTopBarBackground',
73
+      clipToBounds: true
74
+    }
75
+  },
76
+}
77
+```
78
+
65 79
 ## navBarComponentAlignment
66 80
 Align the React view used as the title
67 81
 

+ 1
- 0
lib/ios/RNNBackgroundOptions.h Datei anzeigen

@@ -5,5 +5,6 @@
5 5
 
6 6
 @property (nonatomic, strong) NSNumber* color;
7 7
 @property (nonatomic, strong) RNNComponentOptions* component;
8
+@property (nonatomic, strong) NSNumber* clipToBounds; 
8 9
 
9 10
 @end

+ 5
- 1
lib/ios/RNNRootViewController.m Datei anzeigen

@@ -192,9 +192,13 @@
192 192
 			
193 193
 			_customTopBarBackground = [[RNNCustomTitleView alloc] initWithFrame:self.navigationController.navigationBar.bounds subView:reactView alignment:@"fill"];
194 194
 			[self.navigationController.navigationBar insertSubview:_customTopBarBackground atIndex:1];
195
-			self.navigationController.navigationBar.clipsToBounds = YES;
196 195
 		} else if (self.navigationController.navigationBar.subviews.count && [[self.navigationController.navigationBar.subviews objectAtIndex:1] isKindOfClass:[RNNCustomTitleView class]]) {
197 196
 			[[self.navigationController.navigationBar.subviews objectAtIndex:1] removeFromSuperview];
197
+		}
198
+		
199
+		if (self.options.topBar.background.clipToBounds) {
200
+			self.navigationController.navigationBar.clipsToBounds = YES;
201
+		} else {
198 202
 			self.navigationController.navigationBar.clipsToBounds = NO;
199 203
 		}
200 204
 	} if (_customTopBarBackground && _customTopBarBackground.superview == nil) {

+ 15
- 0
lib/ios/ReactNativeNavigationTests/RNNRootViewControllerTest.m Datei anzeigen

@@ -712,4 +712,19 @@
712 712
 	XCTAssertTrue([attributes[@"NSFont"] isEqual:expectedFont]);
713 713
 }
714 714
 
715
+- (void)testTopBarBackgroundClipToBounds_true {
716
+	self.options.topBar.background.clipToBounds = @(1);
717
+	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
718
+	[self.uut viewWillAppear:false];
719
+
720
+	XCTAssertTrue(self.uut.navigationController.navigationBar.clipsToBounds);
721
+}
722
+
723
+- (void)testTopBarBackgroundClipToBounds_false {
724
+	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
725
+	[self.uut viewWillAppear:false];
726
+
727
+	XCTAssertFalse(self.uut.navigationController.navigationBar.clipsToBounds);
728
+}
729
+
715 730
 @end

+ 5
- 0
lib/src/interfaces/Options.ts Datei anzeigen

@@ -184,6 +184,11 @@ export interface  OptionsTopBarBackground {
184 184
    * Background color of the top bar
185 185
    */
186 186
   color?: Color;
187
+  /**
188
+   * Clip the top bar background to bounds if set to true.
189
+   * #### (iOS specific)
190
+   */
191
+  clipToBounds?: boolean;
187 192
   /**
188 193
    * Set a custom component for the Top Bar background
189 194
    */