mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
dismissSoftInput implemented
This commit is contained in:
@@ -2,13 +2,13 @@
|
||||
import textBase = require("ui/text-base");
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
import enums = require("ui/enums");
|
||||
import utils = require("utils/utils");
|
||||
|
||||
export class EditableTextBase extends common.EditableTextBase {
|
||||
private _android: android.widget.EditText;
|
||||
/* tslint:disable */
|
||||
private _dirtyTextAccumulator: string;
|
||||
/* tslint:enable */
|
||||
private _imm: android.view.inputmethod.InputMethodManager;
|
||||
|
||||
constructor(options?: textBase.Options) {
|
||||
super(options);
|
||||
@@ -18,9 +18,7 @@ export class EditableTextBase extends common.EditableTextBase {
|
||||
return this._android;
|
||||
}
|
||||
|
||||
public _createUI() {
|
||||
this._imm = <android.view.inputmethod.InputMethodManager>this._context.getSystemService(android.content.Context.INPUT_METHOD_SERVICE);
|
||||
|
||||
public _createUI() {
|
||||
this._android = new android.widget.EditText(this._context);
|
||||
this._configureEditText();
|
||||
this.android.setTag(this.android.getKeyListener());
|
||||
@@ -103,23 +101,20 @@ export class EditableTextBase extends common.EditableTextBase {
|
||||
}
|
||||
|
||||
public _onDetached(force?: boolean) {
|
||||
this._imm = undefined;
|
||||
this._android = undefined;
|
||||
|
||||
super._onDetached(force);
|
||||
}
|
||||
|
||||
public dismissSoftInput() {
|
||||
if (this._imm) {
|
||||
this._imm.hideSoftInputFromWindow(this._android.getWindowToken(), 0);
|
||||
}
|
||||
utils.ad.dismissSoftInput(this._nativeView);
|
||||
}
|
||||
|
||||
public focus(): boolean {
|
||||
var result = super.focus();
|
||||
|
||||
if (result && this._nativeView) {
|
||||
this._imm.showSoftInput(this._nativeView, android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT);
|
||||
if (result) {
|
||||
utils.ad.showSoftInput(this._nativeView);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -50,4 +50,7 @@ export class SearchBar extends view.View implements definition.SearchBar {
|
||||
value instanceof color.Color ? value : new color.Color(<any>value));
|
||||
}
|
||||
|
||||
public dismissSoftInput() {
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -96,6 +96,20 @@ global.moduleMerge(common, exports);
|
||||
export class SearchBar extends common.SearchBar {
|
||||
private _android: android.widget.SearchView;
|
||||
|
||||
public dismissSoftInput() {
|
||||
utils.ad.dismissSoftInput(this._nativeView);
|
||||
}
|
||||
|
||||
public focus(): boolean {
|
||||
var result = super.focus();
|
||||
|
||||
if (result) {
|
||||
utils.ad.showSoftInput(this._nativeView);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public _createUI() {
|
||||
this._android = new android.widget.SearchView(this._context);
|
||||
|
||||
|
||||
5
ui/search-bar/search-bar.d.ts
vendored
5
ui/search-bar/search-bar.d.ts
vendored
@@ -78,5 +78,10 @@ declare module "ui/search-bar" {
|
||||
* Raised when a search bar search is closed.
|
||||
*/
|
||||
on(event: "close", callback: (args: observable.EventData) => void, thisArg?: any);
|
||||
|
||||
/**
|
||||
* Hides the soft input method, ususally a soft keyboard.
|
||||
*/
|
||||
dismissSoftInput(): void;
|
||||
}
|
||||
}
|
||||
@@ -115,6 +115,10 @@ export class SearchBar extends common.SearchBar {
|
||||
super.onUnloaded();
|
||||
}
|
||||
|
||||
public dismissSoftInput() {
|
||||
(<UIResponder>this.ios).resignFirstResponder();
|
||||
}
|
||||
|
||||
get ios(): UISearchBar {
|
||||
return this._ios;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user