Explorar el Código

Adding hideNavBarOnFocusSearchBar option (#4578)

* hidesNavigationBarDuringPresentation SearchBar

* Adding hideNavBarOnFocusSearchBar option

* Fixing compilation error

* Code cleanup

* code refactoring
sganti564 hace 6 años
padre
commit
83f69d4eff

+ 1
- 0
lib/ios/RNNTopBarOptions.h Ver fichero

@@ -23,6 +23,7 @@
23 23
 @property (nonatomic, strong) Bool* animate;
24 24
 @property (nonatomic, strong) Bool* searchBar;
25 25
 @property (nonatomic, strong) Bool* searchBarHiddenWhenScrolling;
26
+@property (nonatomic, strong) Bool* hideNavBarOnFocusSearchBar;
26 27
 @property (nonatomic, strong) Text* testID;
27 28
 @property (nonatomic, strong) Text* barStyle;
28 29
 @property (nonatomic, strong) Text* searchBarPlaceholder;

+ 1
- 2
lib/ios/RNNTopBarOptions.m Ver fichero

@@ -14,7 +14,6 @@
14 14
 
15 15
 - (instancetype)initWithDict:(NSDictionary *)dict {
16 16
 	self = [super init];
17
-	
18 17
 	self.visible = [BoolParser parse:dict key:@"visible"];
19 18
 	self.hideOnScroll = [BoolParser parse:dict key:@"hideOnScroll"];
20 19
 	self.leftButtonColor = [ColorParser parse:dict key:@"leftButtonColor"];
@@ -26,6 +25,7 @@
26 25
 	self.animate = [BoolParser parse:dict key:@"animate"];
27 26
 	self.searchBar = [BoolParser parse:dict key:@"searchBar"];
28 27
 	self.searchBarHiddenWhenScrolling = [BoolParser parse:dict key:@"searchBarHiddenWhenScrolling"];
28
+	self.hideNavBarOnFocusSearchBar = [BoolParser parse:dict key:@"hideNavBarOnFocusSearchBar"];
29 29
 	self.testID = [TextParser parse:dict key:@"testID"];
30 30
 	self.barStyle = [TextParser parse:dict key:@"barStyle"];
31 31
 	self.searchBarPlaceholder = [TextParser parse:dict key:@"searchBarPlaceholder"];
@@ -57,7 +57,6 @@
57 57
 	self.leftButtons = dict[@"leftButtons"];
58 58
 	self.rightButtons = dict[@"rightButtons"];
59 59
 	
60
-
61 60
 	return self;
62 61
 }
63 62
 

+ 10
- 2
lib/ios/RNNViewControllerPresenter.m Ver fichero

@@ -29,7 +29,11 @@
29 29
 	}
30 30
 	
31 31
 	if (options.topBar.searchBar.hasValue) {
32
-		[viewController rnn_setSearchBarWithPlaceholder:[options.topBar.searchBarPlaceholder getWithDefaultValue:@""]];
32
+		BOOL hideNavBarOnFocusSearchBar = YES;
33
+		if (options.topBar.hideNavBarOnFocusSearchBar.hasValue) {
34
+			hideNavBarOnFocusSearchBar = options.topBar.hideNavBarOnFocusSearchBar.get;
35
+		}
36
+		[viewController rnn_setSearchBarWithPlaceholder:[options.topBar.searchBarPlaceholder getWithDefaultValue:@""] hideNavBarOnFocusSearchBar: hideNavBarOnFocusSearchBar];
33 37
 	}
34 38
 }
35 39
 
@@ -65,7 +69,11 @@
65 69
 	}
66 70
 	
67 71
 	if (newOptions.topBar.searchBar.hasValue) {
68
-		[viewController rnn_setSearchBarWithPlaceholder:[newOptions.topBar.searchBarPlaceholder getWithDefaultValue:@""]];
72
+		BOOL hideNavBarOnFocusSearchBar = YES;
73
+		if (newOptions.topBar.hideNavBarOnFocusSearchBar.hasValue) {
74
+			hideNavBarOnFocusSearchBar = newOptions.topBar.hideNavBarOnFocusSearchBar.get;
75
+		}
76
+		[viewController rnn_setSearchBarWithPlaceholder:[newOptions.topBar.searchBarPlaceholder getWithDefaultValue:@""] hideNavBarOnFocusSearchBar:hideNavBarOnFocusSearchBar];
69 77
 	}
70 78
 	
71 79
 	if (newOptions.topBar.drawBehind.hasValue) {

+ 1
- 1
lib/ios/UIViewController+RNNOptions.h Ver fichero

@@ -8,7 +8,7 @@
8 8
 
9 9
 - (void)rnn_setModalTransitionStyle:(UIModalTransitionStyle)modalTransitionStyle;
10 10
 
11
-- (void)rnn_setSearchBarWithPlaceholder:(NSString *)placeholder;
11
+- (void)rnn_setSearchBarWithPlaceholder:(NSString *)placeholder hideNavBarOnFocusSearchBar:(BOOL)hideNavBarOnFocusSearchBar;
12 12
 
13 13
 - (void)rnn_setSearchBarHiddenWhenScrolling:(BOOL)searchBarHidden;
14 14
 

+ 3
- 1
lib/ios/UIViewController+RNNOptions.m Ver fichero

@@ -28,7 +28,8 @@ const NSInteger BLUR_STATUS_TAG = 78264801;
28 28
 	self.modalTransitionStyle = modalTransitionStyle;
29 29
 }
30 30
 
31
-- (void)rnn_setSearchBarWithPlaceholder:(NSString *)placeholder {
31
+- (void)rnn_setSearchBarWithPlaceholder:(NSString *)placeholder 
32
+						hideNavBarOnFocusSearchBar:(BOOL)hideNavBarOnFocusSearchBar {
32 33
 	if (@available(iOS 11.0, *)) {
33 34
 		if (!self.navigationItem.searchController) {
34 35
 			UISearchController *search = [[UISearchController alloc]initWithSearchResultsController:nil];
@@ -40,6 +41,7 @@ const NSInteger BLUR_STATUS_TAG = 78264801;
40 41
 			if (placeholder) {
41 42
 				search.searchBar.placeholder = placeholder;
42 43
 			}
44
+			search.hidesNavigationBarDuringPresentation = hideNavBarOnFocusSearchBar;
43 45
 			self.navigationItem.searchController = search;
44 46
 			
45 47
 			// Fixes #3450, otherwise, UIKit will infer the presentation context to be the root most view controller

+ 5
- 0
lib/src/interfaces/Options.ts Ver fichero

@@ -369,6 +369,11 @@ export interface OptionsTopBar {
369 369
    * #### (iOS 11+ specific)
370 370
    */
371 371
   searchBarPlaceholder?: string;
372
+  /**
373
+   * Controls Hiding NavBar on focus UISearchBar
374
+   * #### (iOS 11+ specific)
375
+   */
376
+  hideNavBarOnFocusSearchBar?: boolean;
372 377
   /**
373 378
    * Control the Large Title configuration
374 379
    * #### (iOS 11+ specific)

+ 3
- 1
playground/src/screens/SearchScreen.js Ver fichero

@@ -21,6 +21,7 @@ for(let i = 0; i < 200; i++) {
21 21
 
22 22
 class SearchControllerScreen extends Component {
23 23
   static options() {
24
+   
24 25
     return {
25 26
       topBar: {
26 27
         title: {
@@ -33,7 +34,8 @@ class SearchControllerScreen extends Component {
33 34
         background: {
34 35
           translucent: true
35 36
         },
36
-        searchBarPlaceholder: 'Start Typing'
37
+        searchBarPlaceholder: 'Start Typing',
38
+        hideNavBarOnFocusSearchBar: false
37 39
       }
38 40
     };
39 41
   }