FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge pull request #956 from NativeScript/search-bar-dismissSoftInput · NativeScript/NativeScript@23fc515 · GitHub

Commit 23fc515

Browse files
Vladimir Enchev
committed
Merge pull request #956 from NativeScript/search-bar-dismissSoftInput
dismissSoftInput implemented
2 parents 66a834c + 343265c commit 23fc515

7 files changed

Lines changed: 68 additions & 10 deletions

File tree

‎ui/editable-text-base/editable-text-base.android.ts‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
import textBase = require("ui/text-base");
33
import dependencyObservable = require("ui/core/dependency-observable");
44
import enums = require("ui/enums");
5+
import utils = require("utils/utils");
56

67
export class EditableTextBase extends common.EditableTextBase {
78
private _android: android.widget.EditText;
89
/* tslint:disable */
910
private _dirtyTextAccumulator: string;
1011
/* tslint:enable */
11-
private _imm: android.view.inputmethod.InputMethodManager;
1212

1313
constructor(options?: textBase.Options) {
1414
super(options);
@@ -18,9 +18,7 @@ export class EditableTextBase extends common.EditableTextBase {
1818
return this._android;
1919
}
2020

21-
public _createUI() {
22-
this._imm = <android.view.inputmethod.InputMethodManager>this._context.getSystemService(android.content.Context.INPUT_METHOD_SERVICE);
23-
21+
public _createUI() {
2422
this._android = new android.widget.EditText(this._context);
2523
this._configureEditText();
2624
this.android.setTag(this.android.getKeyListener());
@@ -103,23 +101,20 @@ export class EditableTextBase extends common.EditableTextBase {
103101
}
104102

105103
public _onDetached(force?: boolean) {
106-
this._imm = undefined;
107104
this._android = undefined;
108105

109106
super._onDetached(force);
110107
}
111108

112109
public dismissSoftInput() {
113-
if (this._imm) {
114-
this._imm.hideSoftInputFromWindow(this._android.getWindowToken(), 0);
115-
}
110+
utils.ad.dismissSoftInput(this._nativeView);
116111
}
117112

118113
public focus(): boolean {
119114
var result = super.focus();
120115

121-
if (result && this._nativeView) {
122-
this._imm.showSoftInput(this._nativeView, android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT);
116+
if (result) {
117+
utils.ad.showSoftInput(this._nativeView);
123118
}
124119

125120
return result;

‎ui/search-bar/search-bar-common.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,7 @@ export class SearchBar extends view.View implements definition.SearchBar {
5050
value instanceof color.Color ? value : new color.Color(<any>value));
5151
}
5252

53+
public dismissSoftInput() {
54+
//
55+
}
5356
}

‎ui/search-bar/search-bar.android.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ global.moduleMerge(common, exports);
9696
export class SearchBar extends common.SearchBar {
9797
private _android: android.widget.SearchView;
9898

99+
public dismissSoftInput() {
100+
utils.ad.dismissSoftInput(this._nativeView);
101+
}
102+
103+
public focus(): boolean {
104+
var result = super.focus();
105+
106+
if (result) {
107+
utils.ad.showSoftInput(this._nativeView);
108+
}
109+
110+
return result;
111+
}
112+
99113
public _createUI() {
100114
this._android = new android.widget.SearchView(this._context);
101115

‎ui/search-bar/search-bar.d.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,10 @@ declare module "ui/search-bar" {
7878
* Raised when a search bar search is closed.
7979
*/
8080
on(event: "close", callback: (args: observable.EventData) => void, thisArg?: any);
81+
82+
/**
83+
* Hides the soft input method, ususally a soft keyboard.
84+
*/
85+
dismissSoftInput(): void;
8186
}
8287
}

‎ui/search-bar/search-bar.ios.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ export class SearchBar extends common.SearchBar {
115115
super.onUnloaded();
116116
}
117117

118+
public dismissSoftInput() {
119+
(<UIResponder>this.ios).resignFirstResponder();
120+
}
121+
118122
get ios(): UISearchBar {
119123
return this._ios;
120124
}

‎utils/utils.android.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,28 @@ export module ad {
5151
export function getApplication() { return <android.app.Application>(<any>com.tns).NativeScriptApplication.getInstance(); }
5252
export function getApplicationContext() { return <android.content.Context>getApplication().getApplicationContext(); }
5353

54+
var inputMethodManager: android.view.inputmethod.InputMethodManager;
55+
export function getInputMethodManager() {
56+
if (!inputMethodManager) {
57+
inputMethodManager = <android.view.inputmethod.InputMethodManager>getApplicationContext().getSystemService(android.content.Context.INPUT_METHOD_SERVICE);
58+
}
59+
return inputMethodManager;
60+
}
61+
62+
export function showSoftInput(nativeView: android.view.View) : void {
63+
var imm = getInputMethodManager();
64+
if (imm && nativeView instanceof android.view.View) {
65+
imm.showSoftInput(nativeView, android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT);
66+
}
67+
}
68+
69+
export function dismissSoftInput(nativeView: android.view.View): void {
70+
var imm = getInputMethodManager();
71+
if (imm && nativeView instanceof android.view.View) {
72+
imm.hideSoftInputFromWindow(nativeView.getWindowToken(), 0);
73+
}
74+
}
75+
5476
export module collections {
5577
export function stringArrayToStringSet(str: string[]): any {
5678
var hashSet = new java.util.HashSet();

‎utils/utils.d.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@
6666
*/
6767
export function getApplicationContext(): android.content.Context;
6868

69+
/**
70+
* Gets the native Android input method manager.
71+
*/
72+
export function getInputMethodManager(): android.view.inputmethod.InputMethodManager;
73+
74+
/**
75+
* Hides the soft input method, ususally a soft keyboard.
76+
*/
77+
export function dismissSoftInput(nativeView: android.view.View): void;
78+
79+
/**
80+
* Shows the soft input method, ususally a soft keyboard.
81+
*/
82+
export function showSoftInput(nativeView: android.view.View): void;
83+
6984
/**
7085
* Utility module dealing with some android collections.
7186
*/

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL