Browse Source

Adding hideNavBarOnFocusSearchBar option (#4578)

* hidesNavigationBarDuringPresentation SearchBar

* Adding hideNavBarOnFocusSearchBar option

* Fixing compilation error

* Code cleanup

* code refactoring
sganti564 5 years ago
parent
commit
83f69d4eff

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

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

+ 1
- 2
lib/ios/RNNTopBarOptions.m View File

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

+ 10
- 2
lib/ios/RNNViewControllerPresenter.m View File

29
 	}
29
 	}
30
 	
30
 	
31
 	if (options.topBar.searchBar.hasValue) {
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
 	}
69
 	}
66
 	
70
 	
67
 	if (newOptions.topBar.searchBar.hasValue) {
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
 	if (newOptions.topBar.drawBehind.hasValue) {
79
 	if (newOptions.topBar.drawBehind.hasValue) {

+ 1
- 1
lib/ios/UIViewController+RNNOptions.h View File

8
 
8
 
9
 - (void)rnn_setModalTransitionStyle:(UIModalTransitionStyle)modalTransitionStyle;
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
 - (void)rnn_setSearchBarHiddenWhenScrolling:(BOOL)searchBarHidden;
13
 - (void)rnn_setSearchBarHiddenWhenScrolling:(BOOL)searchBarHidden;
14
 
14
 

+ 3
- 1
lib/ios/UIViewController+RNNOptions.m View File

28
 	self.modalTransitionStyle = modalTransitionStyle;
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
 	if (@available(iOS 11.0, *)) {
33
 	if (@available(iOS 11.0, *)) {
33
 		if (!self.navigationItem.searchController) {
34
 		if (!self.navigationItem.searchController) {
34
 			UISearchController *search = [[UISearchController alloc]initWithSearchResultsController:nil];
35
 			UISearchController *search = [[UISearchController alloc]initWithSearchResultsController:nil];
40
 			if (placeholder) {
41
 			if (placeholder) {
41
 				search.searchBar.placeholder = placeholder;
42
 				search.searchBar.placeholder = placeholder;
42
 			}
43
 			}
44
+			search.hidesNavigationBarDuringPresentation = hideNavBarOnFocusSearchBar;
43
 			self.navigationItem.searchController = search;
45
 			self.navigationItem.searchController = search;
44
 			
46
 			
45
 			// Fixes #3450, otherwise, UIKit will infer the presentation context to be the root most view controller
47
 			// Fixes #3450, otherwise, UIKit will infer the presentation context to be the root most view controller

+ 5
- 0
lib/src/interfaces/Options.ts View File

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

+ 3
- 1
playground/src/screens/SearchScreen.js View File

21
 
21
 
22
 class SearchControllerScreen extends Component {
22
 class SearchControllerScreen extends Component {
23
   static options() {
23
   static options() {
24
+   
24
     return {
25
     return {
25
       topBar: {
26
       topBar: {
26
         title: {
27
         title: {
33
         background: {
34
         background: {
34
           translucent: true
35
           translucent: true
35
         },
36
         },
36
-        searchBarPlaceholder: 'Start Typing'
37
+        searchBarPlaceholder: 'Start Typing',
38
+        hideNavBarOnFocusSearchBar: false
37
       }
39
       }
38
     };
40
     };
39
   }
41
   }