Skip to content

Commit

Permalink
feat(ios) : Added functionality to show search bar in navigation bar …
Browse files Browse the repository at this point in the history
…for TiUIListView and TiUITableView (#10664)

* feat(ios) : Added functionality to show search bar in navigation bar

* feat(ios): Updated doc

* feat(ios): Updated doc

* Added functionality to show search bar in navigation bar for TiUITableView

* feat(ios) : Updated api showSearchBarInNavigation to ’showSearchBarInNavBar’

* feat(ios) : fix UI issue

* feat(ios) : Wrapped functional call under macro
  • Loading branch information
vijaysingh-axway authored and ssjsamir committed Mar 7, 2019
1 parent e5258e1 commit 99be2e2
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 24 deletions.
13 changes: 13 additions & 0 deletions apidoc/Titanium/UI/ListView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,19 @@ properties:
platforms: [iphone, ipad]
availability: creation

- name: showSearchBarInNavBar
summary: A Boolean indicating whether search bar will be in navigation bar.
description: |
If you want to show the search bar in navigation bar, set this property `true` during creation.
Use the <Titanium.UI.Window.hidesSearchBarWhenScrolling> property to control the visibility of the
searchbar when scrolling.
type: Boolean
default: false
since: 8.1.0
platforms: [iphone, ipad]
osver: {ios: {min: "11.0"}}
availability: creation

- name: resultsBackgroundColor
summary: The background color of the search results (iOS-only).
description: |
Expand Down
13 changes: 13 additions & 0 deletions apidoc/Titanium/UI/TableView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,19 @@ properties:
platforms: [iphone, ipad]
availability: creation

- name: showSearchBarInNavBar
summary: A Boolean indicating whether search bar will be in navigation bar.
description: |
If you want to show the search bar in navigation bar, set this property `true` during creation.
Use the <Titanium.UI.Window.hidesSearchBarWhenScrolling> property to control the visibility of the
searchbar when scrolling.
type: Boolean
default: false
since: 8.1.0
platforms: [iphone, ipad]
osver: {ios: {min: "11.0"}}
availability: creation

- name: searchAsChild
summary: Determines whether the [SearchBar](Titanium.UI.SearchBar) or [SearchView](Titanium.UI.Android.SearchView) appears as part of the TableView.
description: Set to false if the search view will be displayed in the action bar.
Expand Down
17 changes: 16 additions & 1 deletion apidoc/Titanium/UI/Window.yml
Original file line number Diff line number Diff line change
Expand Up @@ -555,11 +555,26 @@ properties:
title view when requested by the current navigation item. To specify when
the large out-of-line title view appears, see <Titanium.UI.Window.largeTitleDisplayMode>.
default: false
type: String
type: Boolean
since: "6.3.0"
platforms: [iphone, ipad]
osver: {ios: {min: "11.0"}}

- name: hidesSearchBarWhenScrolling
summary: A Boolean value indicating whether the integrated search bar is hidden when scrolling any underlying content.
description: |
When the value of this property is true, the search bar is visible only when the scroll position
equals the top of your content view. When the user scrolls down, the search bar collapses into
the navigation bar. Scrolling back to the top reveals the search bar again. When the value of
this property is false, the search bar remains regardless of the current scroll position.
You must set <Titanium.UI.ListView.showSearchBarInNavBar> or <Titanium.UI.TableView.showSearchBarInNavBar>
property for this property to have any effect.
default: true
type: Boolean
since: "8.1.0"
platforms: [iphone, ipad]
osver: {ios: {min: "11.0"}}

- name: largeTitleDisplayMode
summary: The mode to use when displaying the title of the navigation bar.
description: |
Expand Down
52 changes: 41 additions & 11 deletions iphone/Classes/TiUIListView.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ @implementation TiUIListView {
CGPoint tableContentOffset;
BOOL isSearched;
UIView *dimmingView;
BOOL isSearchBarInNavigation;
}

#ifdef TI_USE_AUTOLAYOUT
Expand Down Expand Up @@ -193,7 +194,10 @@ - (void)configureHeaders
_searchWrapper = [self initWrapperProxy];
_headerWrapper = [self initWrapperProxy];

[_headerViewProxy add:_searchWrapper];
isSearchBarInNavigation = [TiUtils boolValue:[(TiViewProxy *)self.proxy valueForUndefinedKey:@"showSearchBarInNavBar"] def:NO] && [TiUtils isIOSVersionOrGreater:@"11.0"];
if (!isSearchBarInNavigation) {
[_headerViewProxy add:_searchWrapper];
}
[_headerViewProxy add:_headerWrapper];
}

Expand Down Expand Up @@ -575,17 +579,21 @@ - (void)updateSearchControllerFrames
if (![searchController isActive]) {
return;
}
[dimmingView setFrame:CGRectMake(0, searchController.searchBar.frame.size.height, self.frame.size.width, self.frame.size.height - searchController.searchBar.frame.size.height)];
CGPoint convertedOrigin = [self.superview convertPoint:self.frame.origin toView:searchControllerPresenter.view];
if (isSearchBarInNavigation) {
dimmingView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
} else {
dimmingView.frame = CGRectMake(0, searchController.searchBar.frame.size.height, self.frame.size.width, self.frame.size.height - searchController.searchBar.frame.size.height);
CGPoint convertedOrigin = [self.superview convertPoint:self.frame.origin toView:searchControllerPresenter.view];

UIView *searchSuperView = [searchController.view superview];
searchSuperView.frame = CGRectMake(convertedOrigin.x, convertedOrigin.y, self.frame.size.width, self.frame.size.height);
UIView *searchSuperView = [searchController.view superview];
searchSuperView.frame = CGRectMake(convertedOrigin.x, convertedOrigin.y, self.frame.size.width, self.frame.size.height);

CGFloat width = [_searchWrapper view].frame.size.width;
UIView *view = searchController.searchBar.superview;
view.frame = CGRectMake(0, 0, width, view.frame.size.height);
searchController.searchBar.frame = CGRectMake(0, 0, width, searchController.searchBar.frame.size.height);
[searchViewProxy ensureSearchBarHierarchy];
CGFloat width = [_searchWrapper view].frame.size.width;
UIView *view = searchController.searchBar.superview;
view.frame = CGRectMake(0, 0, width, view.frame.size.height);
searchController.searchBar.frame = CGRectMake(0, 0, width, searchController.searchBar.frame.size.height);
[searchViewProxy ensureSearchBarHierarchy];
}
}

#pragma mark - Public API
Expand Down Expand Up @@ -2188,6 +2196,24 @@ - (void)viewResignFocus

- (void)viewGetFocus
{
#if IS_XCODE_9
if (isSearchBarInNavigation) {
id proxy = [(TiViewProxy *)self.proxy parent];
while ([proxy isKindOfClass:[TiViewProxy class]] && ![proxy isKindOfClass:[TiWindowProxy class]]) {
proxy = [proxy parent];
}
UIViewController *controller;
if ([proxy isKindOfClass:[TiWindowProxy class]]) {
controller = [proxy windowHoldingController];
} else {
controller = [[TiApp app] controller];
}
if (!controller.navigationItem.searchController) {
controller.navigationItem.searchController = searchController;
}
}
#endif

if (isSearched && self.searchedString && ![searchController isActive]) {
isSearched = NO;
[searchController performSelector:@selector(setActive:) withObject:@YES afterDelay:.1];
Expand Down Expand Up @@ -2356,7 +2382,11 @@ - (void)createDimmingView

- (void)showDimmingView
{
dimmingView.frame = CGRectMake(0, searchController.searchBar.frame.size.height, self.frame.size.width, self.frame.size.height - searchController.searchBar.frame.size.height);
if (isSearchBarInNavigation) {
dimmingView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
} else {
dimmingView.frame = CGRectMake(0, searchController.searchBar.frame.size.height, self.frame.size.width, self.frame.size.height - searchController.searchBar.frame.size.height);
}
if (!dimmingView.superview) {
[self addSubview:dimmingView];
[self bringSubviewToFront:dimmingView];
Expand Down
1 change: 1 addition & 0 deletions iphone/Classes/TiUITableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
UIEdgeInsets rowSeparatorInsets;
CGPoint tableContentOffset;
BOOL isSearched;
BOOL isSearchBarInNavigation;
}

@property (nonatomic, assign) BOOL viewWillDetach;
Expand Down
49 changes: 38 additions & 11 deletions iphone/Classes/TiUITableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -1434,17 +1434,21 @@ - (void)updateSearchControllerFrames
if (![searchController isActive]) {
return;
}
[dimmingView setFrame:CGRectMake(0, searchController.searchBar.frame.size.height, self.frame.size.width, self.frame.size.height - searchController.searchBar.frame.size.height)];
CGPoint convertedOrigin = [self.superview convertPoint:self.frame.origin toView:searchControllerPresenter.view];
if (isSearchBarInNavigation) {
dimmingView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
} else {
[dimmingView setFrame:CGRectMake(0, searchController.searchBar.frame.size.height, self.frame.size.width, self.frame.size.height - searchController.searchBar.frame.size.height)];
CGPoint convertedOrigin = [self.superview convertPoint:self.frame.origin toView:searchControllerPresenter.view];

UIView *searchSuperView = [searchController.view superview];
searchSuperView.frame = CGRectMake(convertedOrigin.x, convertedOrigin.y, self.frame.size.width, self.frame.size.height);
UIView *searchSuperView = [searchController.view superview];
searchSuperView.frame = CGRectMake(convertedOrigin.x, convertedOrigin.y, self.frame.size.width, self.frame.size.height);

CGFloat width = [searchField view].frame.size.width;
UIView *view = searchController.searchBar.superview;
view.frame = CGRectMake(0, 0, width, view.frame.size.height);
searchController.searchBar.frame = CGRectMake(0, 0, width, searchController.searchBar.frame.size.height);
[searchField ensureSearchBarHierarchy];
CGFloat width = [searchField view].frame.size.width;
UIView *view = searchController.searchBar.superview;
view.frame = CGRectMake(0, 0, width, view.frame.size.height);
searchController.searchBar.frame = CGRectMake(0, 0, width, searchController.searchBar.frame.size.height);
[searchField ensureSearchBarHierarchy];
}
}

#pragma mark Searchbar-related IBActions
Expand Down Expand Up @@ -1552,7 +1556,9 @@ - (void)updateSearchView
[[searchField searchBar] setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[TiUtils setView:searchView positionRect:wrapperFrame];
[tableHeaderView addSubview:searchView];
[tableview setTableHeaderView:tableHeaderView];
if (!isSearchBarInNavigation) {
[tableview setTableHeaderView:tableHeaderView];
}
[searchView sizeToFit];
}
}
Expand Down Expand Up @@ -1784,12 +1790,16 @@ - (void)setSearch_:(id)search
RELEASE_TO_NIL(searchField);
RELEASE_TO_NIL(searchController);

isSearchBarInNavigation = [TiUtils boolValue:[self.proxy valueForKey:@"showSearchBarInNavBar"] def:NO] && [TiUtils isIOSVersionOrGreater:@"11.0"];

if (search != nil) {
//TODO: now that we're using the search controller, we can move away from
//doing our own custom search screen since the controller gives this to us
//for free
searchField = [search retain];
[searchField windowWillOpen];
if (!isSearchBarInNavigation) {
[searchField windowWillOpen];
}
[searchField setDelegate:self];
[self tableView];
[self updateSearchView];
Expand Down Expand Up @@ -2341,6 +2351,23 @@ - (void)viewResignFocus

- (void)viewGetFocus
{
#if IS_XCODE_9
if (isSearchBarInNavigation) {
id proxy = [(TiViewProxy *)self.proxy parent];
while ([proxy isKindOfClass:[TiViewProxy class]] && ![proxy isKindOfClass:[TiWindowProxy class]]) {
proxy = [proxy parent];
}
UIViewController *controller;
if ([proxy isKindOfClass:[TiWindowProxy class]]) {
controller = [[proxy windowHoldingController] retain];
} else {
controller = [[[TiApp app] controller] retain];
}
if (!controller.navigationItem.searchController) {
controller.navigationItem.searchController = searchController;
}
}
#endif
if (!hideOnSearch && isSearched && self.searchedString && ![searchController isActive]) {
isSearched = NO;
searchController.searchBar.text = self.searchedString;
Expand Down
2 changes: 1 addition & 1 deletion iphone/Classes/TiUITableViewProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ - (void)resignFocus
- (NSArray *)keySequence
{
if (tableKeySequence == nil) {
tableKeySequence = [[NSArray arrayWithObjects:@"style", @"search", @"data", @"backgroundColor", nil] retain];
tableKeySequence = [[NSArray arrayWithObjects:@"style", @"showSearchBarInNavBar", @"search", @"data", @"backgroundColor", nil] retain];
}
return tableKeySequence;
}
Expand Down
13 changes: 13 additions & 0 deletions iphone/TitaniumKit/TitaniumKit/Sources/Modules/TiUIWindowProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,17 @@ - (void)setLargeTitleDisplayMode:(id)value
}
}

- (void)setHidesSearchBarWhenScrolling:(id)value
{
ENSURE_UI_THREAD(setHidesSearchBarWhenScrolling, value);
ENSURE_TYPE_OR_NIL(value, NSNumber);

[self replaceValue:value forKey:@"hidesSearchBarWhenScrolling" notification:NO];

if ([TiUtils isIOSVersionOrGreater:@"11.0"] && shouldUpdateNavBar && controller != nil && [controller navigationController] != nil) {
[controller navigationItem].hidesSearchBarWhenScrolling = [TiUtils intValue:value def:YES];
}
}
- (void)setTitlePrompt:(NSString *)title_
{
ENSURE_UI_THREAD(setTitlePrompt, title_);
Expand Down Expand Up @@ -933,6 +944,8 @@ - (void)setupWindowDecorations
SETPROP(@"titlePrompt", setTitlePrompt);
SETPROP(@"largeTitleEnabled", setLargeTitleEnabled);
SETPROP(@"largeTitleDisplayMode", setLargeTitleDisplayMode);
SETPROP(@"hidesSearchBarWhenScrolling", setHidesSearchBarWhenScrolling);

[self updateTitleView];
SETPROP(@"barColor", setBarColor);
SETPROP(@"navTintColor", setNavTintColor);
Expand Down

0 comments on commit 99be2e2

Please sign in to comment.