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.
This commit is contained in:
Gheric Speiginer
2016-02-11 09:39:34 -05:00
parent 85ff011e19
commit 66f0dd0697

View File

@@ -70,7 +70,6 @@ class UISearchBarDelegateImpl extends NSObject implements UISearchBarDelegate {
public static ObjCProtocols = [UISearchBarDelegate];
private _owner: WeakRef<SearchBar>;
private _searchText: string;
public static initWithOwner(owner: WeakRef<SearchBar>): UISearchBarDelegateImpl {
let delegate = <UISearchBarDelegateImpl>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) {