Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ios) : Added functionality to show search bar in navigation bar for TiUIListView and TiUITableView #10664

Merged
merged 10 commits into from
Mar 7, 2019
12 changes: 12 additions & 0 deletions apidoc/Titanium/UI/ListView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,18 @@ properties:
platforms: [iphone, ipad]
availability: creation

- name: showSearchBarInNavigation
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 <Ti.UI.Window.hidesSearchBarWhenScrolling> property to control the visibility of the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the docs allow to use Ti.UI instead of Titanium.UI these days?

searchbar when scrolling.
type: Boolean
default: false
since: 8.1.0
platforms: [iphone, ipad]
availability: creation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

osver: {ios: {min: "11.0"}}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Thanks!


- name: resultsBackgroundColor
summary: The background color of the search results (iOS-only).
description: |
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 @@ -554,11 +554,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.showSearchBarInNavigation> 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
34 changes: 31 additions & 3 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:@"showSearchBarInNavigation"] def:NO] && [TiUtils isIOSVersionOrGreater:@"11.0"];
if (!isSearchBarInNavigation) {
[_headerViewProxy add:_searchWrapper];
}
[_headerViewProxy add:_headerWrapper];
}

Expand Down Expand Up @@ -575,7 +579,11 @@ - (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)];
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];
Expand Down Expand Up @@ -2188,6 +2196,22 @@ - (void)viewResignFocus

- (void)viewGetFocus
{
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the iOS 11 guard is required here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already taken care while assigning value to variable 'isSearchBarInNavigation'.
isSearchBarInNavigation = [TiUtils boolValue:[(TiViewProxy *)self.proxy valueForUndefinedKey:@"showSearchBarInNavigation"] def:NO] && [TiUtils isIOSVersionOrGreater:@"11.0"];

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vijaysingh-axway Since we still support older Xcode and SDK versions that don't have the searchController property we need the iOS 11 safeguard anyway. Probably something similar to #10729

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@janvennemann Wrapped under macro IS_XCODE_9.

}
}

if (isSearched && self.searchedString && ![searchController isActive]) {
isSearched = NO;
[searchController performSelector:@selector(setActive:) withObject:@YES afterDelay:.1];
Expand Down Expand Up @@ -2356,7 +2380,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
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