mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
This commit is contained in:
@@ -15,6 +15,7 @@ export abstract class EditableTextBase extends TextBase implements EditableTextB
|
||||
public hint: string;
|
||||
|
||||
public abstract dismissSoftInput();
|
||||
public abstract _setInputType(inputType: number): void;
|
||||
}
|
||||
|
||||
// TODO: Why not name it - hintColor property??
|
||||
|
||||
@@ -48,7 +48,7 @@ function initializeEditTextListeners(): void {
|
||||
|
||||
public afterTextChanged(editable: android.text.IEditable) {
|
||||
const owner = this.owner;
|
||||
if (!owner) {
|
||||
if (!owner || owner._inputTypeChange) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -133,6 +133,9 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
|
||||
|
||||
nativeView: android.widget.EditText;
|
||||
private _keyListenerCache: android.text.method.KeyListener;
|
||||
private _inputType: number;
|
||||
|
||||
public _inputTypeChange: boolean;
|
||||
|
||||
public abstract _configureEditText(editText: android.widget.EditText): void;
|
||||
|
||||
@@ -143,6 +146,7 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
|
||||
const editText = new android.widget.EditText(this._context);
|
||||
this._configureEditText(editText);
|
||||
|
||||
this._inputType = editText.getInputType();
|
||||
const listeners = new EditTextListeners(this);
|
||||
editText.addTextChangedListener(listeners);
|
||||
editText.setOnFocusChangeListener(listeners);
|
||||
@@ -159,7 +163,10 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
|
||||
}
|
||||
|
||||
public _disposeNativeView(force?: boolean) {
|
||||
(<any>this.nativeView).listener.owner = null;
|
||||
const nativeView = this.nativeView;
|
||||
(<any>nativeView).listener.owner = null;
|
||||
nativeView.setInputType(this._inputType);
|
||||
this._keyListenerCache = null;
|
||||
}
|
||||
|
||||
public dismissSoftInput() {
|
||||
@@ -167,8 +174,7 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
|
||||
}
|
||||
|
||||
public focus(): boolean {
|
||||
let result = super.focus();
|
||||
|
||||
const result = super.focus();
|
||||
if (result) {
|
||||
ad.showSoftInput(this.nativeView);
|
||||
}
|
||||
@@ -176,12 +182,17 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
|
||||
return result;
|
||||
}
|
||||
|
||||
private _setInputType(inputType): void {
|
||||
let nativeView = this.nativeView;
|
||||
nativeView.setInputType(inputType);
|
||||
public _setInputType(inputType: number): void {
|
||||
const nativeView = this.nativeView;
|
||||
try {
|
||||
this._inputTypeChange = true;
|
||||
nativeView.setInputType(inputType);
|
||||
} finally {
|
||||
this._inputTypeChange = false;
|
||||
}
|
||||
|
||||
// setInputType will change the keyListener so we should cache it again
|
||||
let listener = nativeView.getKeyListener();
|
||||
const listener = nativeView.getKeyListener();
|
||||
if (listener) {
|
||||
this._keyListenerCache = listener;
|
||||
}
|
||||
|
||||
@@ -49,6 +49,13 @@ export class EditableTextBase extends TextBase {
|
||||
* Hides the soft input method, ususally a soft keyboard.
|
||||
*/
|
||||
dismissSoftInput(): void;
|
||||
|
||||
//@private
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
public _setInputType(inputType: number): void;
|
||||
//@endprivate
|
||||
}
|
||||
|
||||
export type KeyboardType = "datetime" | "phone" | "number" | "url" | "email";
|
||||
|
||||
@@ -10,12 +10,6 @@ export class TextField extends TextFieldBase {
|
||||
editText.setHorizontallyScrolling(true);
|
||||
}
|
||||
|
||||
public initNativeView(): void {
|
||||
// TODO: We should be able to reset it using only our properties. Check it first.
|
||||
super.initNativeView();
|
||||
this.nativeView.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_NORMAL | android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
|
||||
}
|
||||
|
||||
public _onReturnPress() {
|
||||
this.notify({ eventName: TextField.returnPressEvent, object: this })
|
||||
}
|
||||
@@ -48,7 +42,7 @@ export class TextField extends TextFieldBase {
|
||||
}
|
||||
}
|
||||
|
||||
nativeView.setInputType(newInputType);
|
||||
this._setInputType(newInputType);
|
||||
}
|
||||
|
||||
[whiteSpaceProperty.getDefault](): WhiteSpace {
|
||||
|
||||
@@ -4,16 +4,11 @@ import { EditableTextBase } from "../editable-text-base";
|
||||
export * from "../text-base";
|
||||
|
||||
export class TextView extends EditableTextBase implements TextViewDefinition {
|
||||
|
||||
public _configureEditText(editText: android.widget.EditText) {
|
||||
editText.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_NORMAL | android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | android.text.InputType.TYPE_TEXT_FLAG_MULTI_LINE);
|
||||
editText.setGravity(android.view.Gravity.TOP | android.view.Gravity.LEFT);
|
||||
}
|
||||
|
||||
public initNativeView(): void {
|
||||
// TODO: We should be able to reset it using only our properties. Check it first.
|
||||
super.initNativeView();
|
||||
this.nativeView.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_NORMAL | android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | android.text.InputType.TYPE_TEXT_FLAG_MULTI_LINE);
|
||||
}
|
||||
}
|
||||
|
||||
// TextView.prototype.recycleNativeView = true;
|
||||
2
tns-core-modules/ui/text-view/text-view.d.ts
vendored
2
tns-core-modules/ui/text-view/text-view.d.ts
vendored
@@ -18,4 +18,4 @@ export class TextView extends EditableTextBase {
|
||||
* Gets the native iOS [UITextView](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextView_Class/) that represents the user interface for this component. Valid only when running on iOS.
|
||||
*/
|
||||
ios: any /* UITextView */;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user