mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
Fix android search-bar bug (#5046)
* Fix android search-bar bug Searching twice for the same item in the search bar leads to a bug where `submit` event won't be raised. This PR fixes https://github.com/NativeScript/NativeScript/issues/5039 * test: include new test page
This commit is contained in:
27
apps/app/ui-tests-app/search-bar/issue-5039-view-model.ts
Normal file
27
apps/app/ui-tests-app/search-bar/issue-5039-view-model.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { Observable } from 'tns-core-modules/data/observable'
|
||||
import { ObservableArray } from 'tns-core-modules/data/observable-array'
|
||||
import { SearchBar } from 'tns-core-modules/ui/search-bar';
|
||||
|
||||
export class Issue5039ViewModel extends Observable {
|
||||
|
||||
private _items = ['apple', 'apple cider', 'apple pie', 'orange', 'orange juice', 'strawberry', 'blueberry']
|
||||
public items = new ObservableArray()
|
||||
|
||||
constructor(private _searchBar: SearchBar) {
|
||||
super()
|
||||
this.items.push(this._items)
|
||||
}
|
||||
|
||||
onSubmit() {
|
||||
this.filter(this._searchBar.text);
|
||||
}
|
||||
|
||||
clearSearch() {
|
||||
this.filter();
|
||||
}
|
||||
|
||||
filter(value: string = '') {
|
||||
this.items.splice(0, this.items.length) // remove all items
|
||||
this.items.push(this._items.filter(i => -1 !== i.indexOf(value)))
|
||||
}
|
||||
}
|
9
apps/app/ui-tests-app/search-bar/issue-5039.ts
Normal file
9
apps/app/ui-tests-app/search-bar/issue-5039.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { Issue5039ViewModel } from './issue-5039-view-model'
|
||||
import { SearchBar } from "tns-core-modules/ui/search-bar";
|
||||
import { Page } from "tns-core-modules/ui/page";
|
||||
|
||||
export function navigatingTo(args) {
|
||||
const page = <Page>args.object;
|
||||
const searchBar = <SearchBar>page.getViewById("searchBar")
|
||||
page.bindingContext = new Issue5039ViewModel(searchBar);
|
||||
}
|
10
apps/app/ui-tests-app/search-bar/issue-5039.xml
Normal file
10
apps/app/ui-tests-app/search-bar/issue-5039.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo">
|
||||
<StackLayout>
|
||||
<SearchBar id="searchBar" hint="Search" submit="{{ onSubmit }}" clear="{{ clearSearch }}" />
|
||||
<ListView items="{{ items }}">
|
||||
<ListView.itemTemplate>
|
||||
<Label text="{{ $value }}" />
|
||||
</ListView.itemTemplate>
|
||||
</ListView>
|
||||
</StackLayout>
|
||||
</Page>
|
@ -13,5 +13,6 @@ export function loadExamples() {
|
||||
const examples = new Map<string, string>();
|
||||
examples.set("issue-4147", "search-bar/issue-4147");
|
||||
examples.set("search-bar", "search-bar/search-bar");
|
||||
examples.set("issue-5039","search-bar/issue-5039");
|
||||
return examples;
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ function initializeNativeClasses(): void {
|
||||
}
|
||||
|
||||
this[SEARCHTEXT] = newText;
|
||||
this[QUERY] = undefined;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user