mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00
Use AppCompat SearchView (#4371)
* Use AppCompat SearchView * GetNative elements for appcompat * Classes renamed * test modified
This commit is contained in:

committed by
GitHub

parent
4319ca5fc5
commit
1d20845b7c
@ -5,11 +5,10 @@
|
|||||||
<NavigationButton text="Go Back" android.systemIcon="ic_menu_back" tap="onNavBtnTap"/>
|
<NavigationButton text="Go Back" android.systemIcon="ic_menu_back" tap="onNavBtnTap"/>
|
||||||
</ActionBar>
|
</ActionBar>
|
||||||
</Page.actionBar>
|
</Page.actionBar>
|
||||||
<StackLayout>
|
<GridLayout rows="auto auto auto auto *">
|
||||||
<!--The background-color shouldn't be inherit but in Android it is-->
|
<SearchBar row="0" id="bg-color" hint="bg-color" text="" textFieldHintColor="green" />
|
||||||
<SearchBar id="bg-color" hint="bg-color" text="" textFieldHintColor="green" />
|
<SearchBar row="1" class="color" hint="color" text="color" />
|
||||||
<SearchBar class="color" hint="color" text="color" />
|
<SearchBar row="2" hint="Hint Text" id="searchBar" textFieldHintColor="#FFFFFF" style="color:#FFFFFF;background-color: #795548;height:60" />
|
||||||
<SearchBar hint="Hint Text" id="searchBar" textFieldHintColor="#FFFFFF" style="color:#FFFFFF;background-color: #795548;height:60" />
|
<SearchBar row="3" hint="Hint Text" textFieldHintColor="#FFFFFF" textFieldBackgroundColor="red" style="background-color:green;" />
|
||||||
<SearchBar hint="Hint Text" textFieldHintColor="#FFFFFF" textFieldBackgroundColor="red" style="background-color:green;" />
|
</GridLayout>
|
||||||
</StackLayout>
|
|
||||||
</Page>
|
</Page>
|
@ -4,9 +4,10 @@ import * as utils from "tns-core-modules/utils/utils";
|
|||||||
|
|
||||||
function getTextView(bar: android.widget.SearchView): android.widget.TextView {
|
function getTextView(bar: android.widget.SearchView): android.widget.TextView {
|
||||||
if (bar) {
|
if (bar) {
|
||||||
var id = bar.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
|
const pkgName = bar.getContext().getPackageName();
|
||||||
|
var id = bar.getContext().getResources().getIdentifier("search_src_text", "id", pkgName);
|
||||||
if (id) {
|
if (id) {
|
||||||
return <android.widget.TextView> bar.findViewById(id);
|
return <android.widget.TextView>bar.findViewById(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,11 +11,11 @@ const SEARCHTEXT = Symbol("searchText");
|
|||||||
const QUERY = Symbol("query");
|
const QUERY = Symbol("query");
|
||||||
|
|
||||||
interface QueryTextListener {
|
interface QueryTextListener {
|
||||||
new (owner: SearchBar): android.widget.SearchView.OnQueryTextListener;
|
new (owner: SearchBar): android.support.v7.widget.SearchView.OnQueryTextListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CloseListener {
|
interface CloseListener {
|
||||||
new (owner: SearchBar): android.widget.SearchView.OnCloseListener;
|
new (owner: SearchBar): android.support.v7.widget.SearchView.OnCloseListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
let QueryTextListener: QueryTextListener;
|
let QueryTextListener: QueryTextListener;
|
||||||
@ -26,8 +26,8 @@ function initializeNativeClasses(): void {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Interfaces([android.widget.SearchView.OnQueryTextListener])
|
@Interfaces([android.support.v7.widget.SearchView.OnQueryTextListener])
|
||||||
class QueryTextListenerImpl extends java.lang.Object implements android.widget.SearchView.OnQueryTextListener {
|
class CompatQueryTextListenerImpl extends java.lang.Object implements android.support.v7.widget.SearchView.OnQueryTextListener {
|
||||||
constructor(private owner: SearchBar) {
|
constructor(private owner: SearchBar) {
|
||||||
super();
|
super();
|
||||||
return global.__native(this);
|
return global.__native(this);
|
||||||
@ -58,8 +58,8 @@ function initializeNativeClasses(): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Interfaces([android.widget.SearchView.OnCloseListener])
|
@Interfaces([android.support.v7.widget.SearchView.OnCloseListener])
|
||||||
class CloseListenerImpl extends java.lang.Object implements android.widget.SearchView.OnCloseListener {
|
class CompatCloseListenerImpl extends java.lang.Object implements android.support.v7.widget.SearchView.OnCloseListener {
|
||||||
constructor(private owner: SearchBar) {
|
constructor(private owner: SearchBar) {
|
||||||
super();
|
super();
|
||||||
return global.__native(this);
|
return global.__native(this);
|
||||||
@ -71,12 +71,14 @@ function initializeNativeClasses(): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryTextListener = QueryTextListenerImpl;
|
QueryTextListener = CompatQueryTextListenerImpl;
|
||||||
CloseListener = CloseListenerImpl;
|
CloseListener = CompatCloseListenerImpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SearchBar extends SearchBarBase {
|
export class SearchBar extends SearchBarBase {
|
||||||
nativeView: android.widget.SearchView;
|
nativeView: android.support.v7.widget.SearchView;
|
||||||
|
private _searchTextView: android.widget.TextView;
|
||||||
|
private _searchPlate: android.widget.LinearLayout;
|
||||||
|
|
||||||
public dismissSoftInput() {
|
public dismissSoftInput() {
|
||||||
ad.dismissSoftInput(this.nativeView);
|
ad.dismissSoftInput(this.nativeView);
|
||||||
@ -93,7 +95,7 @@ export class SearchBar extends SearchBarBase {
|
|||||||
|
|
||||||
public createNativeView() {
|
public createNativeView() {
|
||||||
initializeNativeClasses();
|
initializeNativeClasses();
|
||||||
const nativeView = new android.widget.SearchView(this._context);
|
const nativeView = new android.support.v7.widget.SearchView(this._context)
|
||||||
nativeView.setIconified(false);
|
nativeView.setIconified(false);
|
||||||
|
|
||||||
const queryTextListener = new QueryTextListener(this);
|
const queryTextListener = new QueryTextListener(this);
|
||||||
@ -118,6 +120,8 @@ export class SearchBar extends SearchBarBase {
|
|||||||
const nativeView: any = this.nativeView;
|
const nativeView: any = this.nativeView;
|
||||||
nativeView.closeListener.owner = null;
|
nativeView.closeListener.owner = null;
|
||||||
nativeView.queryTextListener.owner = null;
|
nativeView.queryTextListener.owner = null;
|
||||||
|
this._searchPlate = null;
|
||||||
|
this._searchTextView = null;
|
||||||
super.disposeNativeView();
|
super.disposeNativeView();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,12 +212,22 @@ export class SearchBar extends SearchBarBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _getTextView(): android.widget.TextView {
|
private _getTextView(): android.widget.TextView {
|
||||||
const id = this.nativeView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
|
if (!this._searchTextView) {
|
||||||
return <android.widget.TextView>this.nativeView.findViewById(id);
|
const pkgName = this.nativeView.getContext().getPackageName();
|
||||||
|
const id = this.nativeView.getContext().getResources().getIdentifier("search_src_text", "id", pkgName);
|
||||||
|
this._searchTextView = <android.widget.TextView>this.nativeView.findViewById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this._searchTextView;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getSearchPlate(): android.widget.LinearLayout {
|
private _getSearchPlate(): android.widget.LinearLayout {
|
||||||
const id = this.nativeView.getContext().getResources().getIdentifier("android:id/search_plate", null, null);
|
if (!this._searchPlate) {
|
||||||
return <android.widget.LinearLayout>this.nativeView.findViewById(id);
|
const pkgName = this.nativeView.getContext().getPackageName();
|
||||||
|
const id = this.nativeView.getContext().getResources().getIdentifier("search_plate", "id", pkgName);
|
||||||
|
this._searchPlate = <android.widget.LinearLayout>this.nativeView.findViewById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this._searchPlate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user