mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
dismissSoftInput implemented
This commit is contained in:
@ -2,13 +2,13 @@
|
|||||||
import textBase = require("ui/text-base");
|
import textBase = require("ui/text-base");
|
||||||
import dependencyObservable = require("ui/core/dependency-observable");
|
import dependencyObservable = require("ui/core/dependency-observable");
|
||||||
import enums = require("ui/enums");
|
import enums = require("ui/enums");
|
||||||
|
import utils = require("utils/utils");
|
||||||
|
|
||||||
export class EditableTextBase extends common.EditableTextBase {
|
export class EditableTextBase extends common.EditableTextBase {
|
||||||
private _android: android.widget.EditText;
|
private _android: android.widget.EditText;
|
||||||
/* tslint:disable */
|
/* tslint:disable */
|
||||||
private _dirtyTextAccumulator: string;
|
private _dirtyTextAccumulator: string;
|
||||||
/* tslint:enable */
|
/* tslint:enable */
|
||||||
private _imm: android.view.inputmethod.InputMethodManager;
|
|
||||||
|
|
||||||
constructor(options?: textBase.Options) {
|
constructor(options?: textBase.Options) {
|
||||||
super(options);
|
super(options);
|
||||||
@ -19,8 +19,6 @@ export class EditableTextBase extends common.EditableTextBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public _createUI() {
|
public _createUI() {
|
||||||
this._imm = <android.view.inputmethod.InputMethodManager>this._context.getSystemService(android.content.Context.INPUT_METHOD_SERVICE);
|
|
||||||
|
|
||||||
this._android = new android.widget.EditText(this._context);
|
this._android = new android.widget.EditText(this._context);
|
||||||
this._configureEditText();
|
this._configureEditText();
|
||||||
this.android.setTag(this.android.getKeyListener());
|
this.android.setTag(this.android.getKeyListener());
|
||||||
@ -103,23 +101,20 @@ export class EditableTextBase extends common.EditableTextBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public _onDetached(force?: boolean) {
|
public _onDetached(force?: boolean) {
|
||||||
this._imm = undefined;
|
|
||||||
this._android = undefined;
|
this._android = undefined;
|
||||||
|
|
||||||
super._onDetached(force);
|
super._onDetached(force);
|
||||||
}
|
}
|
||||||
|
|
||||||
public dismissSoftInput() {
|
public dismissSoftInput() {
|
||||||
if (this._imm) {
|
utils.ad.dismissSoftInput(this._nativeView);
|
||||||
this._imm.hideSoftInputFromWindow(this._android.getWindowToken(), 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public focus(): boolean {
|
public focus(): boolean {
|
||||||
var result = super.focus();
|
var result = super.focus();
|
||||||
|
|
||||||
if (result && this._nativeView) {
|
if (result) {
|
||||||
this._imm.showSoftInput(this._nativeView, android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT);
|
utils.ad.showSoftInput(this._nativeView);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
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));
|
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 {
|
export class SearchBar extends common.SearchBar {
|
||||||
private _android: android.widget.SearchView;
|
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() {
|
public _createUI() {
|
||||||
this._android = new android.widget.SearchView(this._context);
|
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.
|
* Raised when a search bar search is closed.
|
||||||
*/
|
*/
|
||||||
on(event: "close", callback: (args: observable.EventData) => void, thisArg?: any);
|
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();
|
super.onUnloaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public dismissSoftInput() {
|
||||||
|
(<UIResponder>this.ios).resignFirstResponder();
|
||||||
|
}
|
||||||
|
|
||||||
get ios(): UISearchBar {
|
get ios(): UISearchBar {
|
||||||
return this._ios;
|
return this._ios;
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,28 @@ export module ad {
|
|||||||
export function getApplication() { return <android.app.Application>(<any>com.tns).NativeScriptApplication.getInstance(); }
|
export function getApplication() { return <android.app.Application>(<any>com.tns).NativeScriptApplication.getInstance(); }
|
||||||
export function getApplicationContext() { return <android.content.Context>getApplication().getApplicationContext(); }
|
export function getApplicationContext() { return <android.content.Context>getApplication().getApplicationContext(); }
|
||||||
|
|
||||||
|
var inputMethodManager: android.view.inputmethod.InputMethodManager;
|
||||||
|
export function getInputMethodManager() {
|
||||||
|
if (!inputMethodManager) {
|
||||||
|
inputMethodManager = <android.view.inputmethod.InputMethodManager>getApplicationContext().getSystemService(android.content.Context.INPUT_METHOD_SERVICE);
|
||||||
|
}
|
||||||
|
return inputMethodManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function showSoftInput(nativeView: android.view.View) : void {
|
||||||
|
var imm = getInputMethodManager();
|
||||||
|
if (imm && nativeView instanceof android.view.View) {
|
||||||
|
imm.showSoftInput(nativeView, android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function dismissSoftInput(nativeView: android.view.View): void {
|
||||||
|
var imm = getInputMethodManager();
|
||||||
|
if (imm && nativeView instanceof android.view.View) {
|
||||||
|
imm.hideSoftInputFromWindow(nativeView.getWindowToken(), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export module collections {
|
export module collections {
|
||||||
export function stringArrayToStringSet(str: string[]): any {
|
export function stringArrayToStringSet(str: string[]): any {
|
||||||
var hashSet = new java.util.HashSet();
|
var hashSet = new java.util.HashSet();
|
||||||
|
15
utils/utils.d.ts
vendored
15
utils/utils.d.ts
vendored
@ -66,6 +66,21 @@
|
|||||||
*/
|
*/
|
||||||
export function getApplicationContext(): android.content.Context;
|
export function getApplicationContext(): android.content.Context;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the native Android input method manager.
|
||||||
|
*/
|
||||||
|
export function getInputMethodManager(): android.view.inputmethod.InputMethodManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hides the soft input method, ususally a soft keyboard.
|
||||||
|
*/
|
||||||
|
export function dismissSoftInput(nativeView: android.view.View): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows the soft input method, ususally a soft keyboard.
|
||||||
|
*/
|
||||||
|
export function showSoftInput(nativeView: android.view.View): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility module dealing with some android collections.
|
* Utility module dealing with some android collections.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user