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

dismissSoftInput implemented by enchev · Pull Request #956 · NativeScript/NativeScript · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (7) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
15 changes: 5 additions & 10 deletions ui/editable-text-base/editable-text-base.android.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions ui/search-bar/search-bar-common.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
//
}
}
14 changes: 14 additions & 0 deletions ui/search-bar/search-bar.android.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 5 additions & 0 deletions ui/search-bar/search-bar.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
4 changes: 4 additions & 0 deletions ui/search-bar/search-bar.ios.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ export class SearchBar extends common.SearchBar {
super.onUnloaded();
}

public dismissSoftInput() {
(<UIResponder>this.ios).resignFirstResponder();
}

get ios(): UISearchBar {
return this._ios;
}
Expand Down
22 changes: 22 additions & 0 deletions utils/utils.android.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,28 @@ export module ad {
export function getApplication() { return <android.app.Application>(<any>com.tns).NativeScriptApplication.getInstance(); }
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 function stringArrayToStringSet(str: string[]): any {
var hashSet = new java.util.HashSet();
Expand Down
15 changes: 15 additions & 0 deletions utils/utils.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@
*/
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.
*/
Expand Down

Back | FazBrowse Home | New Git URL