From 66f0dd069716fc87a8a2eab1b5142908680dc6df Mon Sep 17 00:00:00 2001 From: Gheric Speiginer Date: Thu, 11 Feb 2016 09:39:34 -0500 Subject: [PATCH] Fix clearEvent after programmatically setting text searchBarTextDidChange only fires when the user changes the text. In the following scenario, clearEvent was not being fired: 1. User clears the text (clearEvent is fired) 2. Text is programmatically set to a non-empty string 3. User clears the text again (clearEvent is not fired) This PR allows the clearEvent to fire at step 3. I would also suggest that a separate event be used when the cancel button is clicked (cancelEvent), as cancel button being clicked does not imply that the text is or should be cleared. --- ui/search-bar/search-bar.ios.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ui/search-bar/search-bar.ios.ts b/ui/search-bar/search-bar.ios.ts index 1ece867c5..4e029fcd6 100644 --- a/ui/search-bar/search-bar.ios.ts +++ b/ui/search-bar/search-bar.ios.ts @@ -70,7 +70,6 @@ class UISearchBarDelegateImpl extends NSObject implements UISearchBarDelegate { public static ObjCProtocols = [UISearchBarDelegate]; private _owner: WeakRef; - private _searchText: string; public static initWithOwner(owner: WeakRef): UISearchBarDelegateImpl { let delegate = UISearchBarDelegateImpl.new(); @@ -87,11 +86,9 @@ class UISearchBarDelegateImpl extends NSObject implements UISearchBarDelegate { owner._onPropertyChangedFromNative(common.SearchBar.textProperty, searchText); // This code is needed since sometimes searchBarCancelButtonClicked is not called! - if (searchText === "" && this._searchText !== searchText) { + if (searchText === "") { owner._emit(common.SearchBar.clearEvent); } - - this._searchText = searchText; } public searchBarCancelButtonClicked(searchBar: UISearchBar) {