From 873f711a6b2c7b3ca50142f434cde49a2f2ebf49 Mon Sep 17 00:00:00 2001 From: Dimitris-Rafail Katsampas Date: Mon, 15 Apr 2024 03:07:25 +0300 Subject: [PATCH] revert: "fix(android): proper change of input interaction mode programmatically (#10434) (#10512) This reverts commit 07d2129f9c9b387c238c9a7c2da29b5690bac986. --- .../ui/editable-text-base/index.android.ts | 25 ++------ packages/core/ui/scroll-view/index.android.ts | 2 +- packages/core/ui/search-bar/index.android.ts | 15 +---- packages/core/ui/text-base/index.android.ts | 31 +++++---- packages/core/ui/text-base/index.d.ts | 5 -- .../core/ui/text-base/text-base-common.ts | 4 -- packages/core/ui/text-field/index.android.ts | 63 +++++-------------- 7 files changed, 39 insertions(+), 106 deletions(-) diff --git a/packages/core/ui/editable-text-base/index.android.ts b/packages/core/ui/editable-text-base/index.android.ts index 9bd7d3b44..cab7db0e1 100644 --- a/packages/core/ui/editable-text-base/index.android.ts +++ b/packages/core/ui/editable-text-base/index.android.ts @@ -1,6 +1,5 @@ import { EditableTextBase as EditableTextBaseCommon, autofillTypeProperty, keyboardTypeProperty, returnKeyTypeProperty, editableProperty, autocapitalizationTypeProperty, autocorrectProperty, hintProperty, placeholderColorProperty, maxLengthProperty } from './editable-text-base-common'; import { textTransformProperty, textProperty, resetSymbol } from '../text-base'; -import { isUserInteractionEnabledProperty } from '../core/view'; import { Color } from '../../color'; import { ad } from '../../utils'; import { SDK_VERSION } from '../../utils/constants'; @@ -178,8 +177,13 @@ export abstract class EditableTextBase extends EditableTextBaseCommon { this._keyListenerCache = listener; } + // clear these fields instead of clearing listener. + // this allows input Type to be changed even after editable is false. if (!this.editable) { - nativeView.setKeyListener(null); + nativeView.setFocusable(false); + nativeView.setFocusableInTouchMode(false); + nativeView.setLongClickable(false); + nativeView.setClickable(false); } } @@ -352,9 +356,6 @@ export abstract class EditableTextBase extends EditableTextBaseCommon { if (value) { nativeView.setKeyListener(this._keyListenerCache); } else { - // Dismiss input if property changes to false programmatically or user will keep typing - this.dismissSoftInput(); - if (!this._keyListenerCache) { this._keyListenerCache = nativeView.getKeyListener(); } @@ -476,20 +477,6 @@ export abstract class EditableTextBase extends EditableTextBaseCommon { } } - [isUserInteractionEnabledProperty.setNative](value) { - const nativeView = this.nativeTextViewProtected; - - // Dismiss input before view loses focus - if (!value) { - this.dismissSoftInput(); - } - - nativeView.setClickable(value); - nativeView.setFocusable(value); - nativeView.setFocusableInTouchMode(value); - nativeView.setLongClickable(value); - } - public setSelection(start: number, stop?: number) { const view = this.nativeTextViewProtected; if (view) { diff --git a/packages/core/ui/scroll-view/index.android.ts b/packages/core/ui/scroll-view/index.android.ts index 352b67a77..5b0b2b1e6 100644 --- a/packages/core/ui/scroll-view/index.android.ts +++ b/packages/core/ui/scroll-view/index.android.ts @@ -1,7 +1,7 @@ import { ScrollEventData } from '.'; import { ScrollViewBase, scrollBarIndicatorVisibleProperty, isScrollEnabledProperty } from './scroll-view-common'; -import { isUserInteractionEnabledProperty } from '../core/view'; import { layout } from '../../utils'; +import { isUserInteractionEnabledProperty } from '../core/view'; export * from './scroll-view-common'; diff --git a/packages/core/ui/search-bar/index.android.ts b/packages/core/ui/search-bar/index.android.ts index 947a48d7e..dead0caf6 100644 --- a/packages/core/ui/search-bar/index.android.ts +++ b/packages/core/ui/search-bar/index.android.ts @@ -1,9 +1,9 @@ import { Font } from '../styling/font'; import { SearchBarBase, textProperty, hintProperty, textFieldHintColorProperty, textFieldBackgroundColorProperty } from './search-bar-common'; import { isUserInteractionEnabledProperty, isEnabledProperty } from '../core/view'; -import { colorProperty, backgroundColorProperty, backgroundInternalProperty, fontInternalProperty, fontSizeProperty } from '../styling/style-properties'; import { ad } from '../../utils'; import { Color } from '../../color'; +import { colorProperty, backgroundColorProperty, backgroundInternalProperty, fontInternalProperty, fontSizeProperty } from '../styling/style-properties'; export * from './search-bar-common'; @@ -97,19 +97,6 @@ function enableSearchView(nativeView: any, value: boolean) { } function enableUserInteractionSearchView(nativeView: any, value: boolean) { - if (nativeView instanceof android.widget.TextView) { - // Dismiss input before view loses focus - if (!value) { - ad.dismissSoftInput(nativeView); - } - - nativeView.setClickable(value); - nativeView.setFocusable(value); - nativeView.setFocusableInTouchMode(value); - nativeView.setLongClickable(value); - return; - } - nativeView.setClickable(value); nativeView.setFocusable(value); diff --git a/packages/core/ui/text-base/index.android.ts b/packages/core/ui/text-base/index.android.ts index 814544392..cb538617b 100644 --- a/packages/core/ui/text-base/index.android.ts +++ b/packages/core/ui/text-base/index.android.ts @@ -223,18 +223,6 @@ export class TextBase extends TextBaseCommon { this._maxHeight = this._maxLines = undefined; } - createFormattedTextNative(value: FormattedString) { - return createSpannableStringBuilder(value, this.style.fontSize); - } - - _getNativeTextTransform(value: CoreTypes.TextTransformType): android.text.method.TransformationMethod { - if (value === 'initial') { - return this._defaultTransformationMethod; - } - - return new TextTransformation(this); - } - [textProperty.getDefault](): symbol | number { return resetSymbol; } @@ -249,11 +237,12 @@ export class TextBase extends TextBaseCommon { this._setNativeText(reset); } - [textStrokeProperty.setNative](value: StrokeCSSValues) { this._setNativeText(); } - + createFormattedTextNative(value: FormattedString) { + return createSpannableStringBuilder(value, this.style.fontSize); + } [formattedTextProperty.setNative](value: FormattedString) { const nativeView = this.nativeTextViewProtected; if (!value) { @@ -282,10 +271,18 @@ export class TextBase extends TextBaseCommon { } [textTransformProperty.setNative](value: CoreTypes.TextTransformType) { - const transformationMethod = this._getNativeTextTransform(value); - if (transformationMethod != null) { - this.nativeTextViewProtected.setTransformationMethod(transformationMethod); + if (value === 'initial') { + this.nativeTextViewProtected.setTransformationMethod(this._defaultTransformationMethod); + + return; } + + // Don't change the transformation method if this is secure TextField or we'll lose the hiding characters. + if ((this).secure) { + return; + } + + this.nativeTextViewProtected.setTransformationMethod(new TextTransformation(this)); } [textAlignmentProperty.getDefault](): CoreTypes.TextAlignmentType { diff --git a/packages/core/ui/text-base/index.d.ts b/packages/core/ui/text-base/index.d.ts index 4d2ea4f77..aeb8ee8ca 100644 --- a/packages/core/ui/text-base/index.d.ts +++ b/packages/core/ui/text-base/index.d.ts @@ -130,11 +130,6 @@ export class TextBase extends View implements AddChildFromBuilder { */ _setNativeText(reset?: boolean): void; - /** - * @private - */ - _getNativeTextTransform(value: CoreTypes.TextTransformType): android.text.method.TransformationMethod; - /** * @private */ diff --git a/packages/core/ui/text-base/text-base-common.ts b/packages/core/ui/text-base/text-base-common.ts index d01cf287b..c7b858aab 100644 --- a/packages/core/ui/text-base/text-base-common.ts +++ b/packages/core/ui/text-base/text-base-common.ts @@ -212,10 +212,6 @@ export abstract class TextBaseCommon extends View implements TextBaseDefinition _setNativeText(reset = false): void { // } - - _getNativeTextTransform(value: CoreTypes.TextTransformType): any { - // - } } TextBaseCommon.prototype._isSingleLine = false; diff --git a/packages/core/ui/text-field/index.android.ts b/packages/core/ui/text-field/index.android.ts index aa428c7bf..66fd1ce16 100644 --- a/packages/core/ui/text-field/index.android.ts +++ b/packages/core/ui/text-field/index.android.ts @@ -6,10 +6,6 @@ import { CoreTypes } from '../../core-types'; export * from './text-field-common'; export class TextField extends TextFieldBase { - nativeViewProtected: android.widget.EditText; - - private _pendingTransformationMethod: android.text.method.TransformationMethod; - 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_NO_SUGGESTIONS); editText.setLines(1); @@ -21,52 +17,43 @@ export class TextField extends TextFieldBase { this.notify({ eventName: TextField.returnPressEvent, object: this }); } - public disposeNativeView(): void { - this._pendingTransformationMethod = null; - super.disposeNativeView(); + [secureProperty.setNative]() { + this.setSecureAndKeyboardType(); } - _getNativeTextTransform(value: CoreTypes.TextTransformType): android.text.method.TransformationMethod { - const transformationMethod = super._getNativeTextTransform(value); - - if (this.secure) { - this._pendingTransformationMethod = transformationMethod; - return null; - } - - return transformationMethod; + [keyboardTypeProperty.setNative]() { + this.setSecureAndKeyboardType(); } setSecureAndKeyboardType(): void { let inputType: number; - const nativeView = this.nativeTextViewProtected; - const numericKeyboardType = +this.keyboardType; + // Check for a passed in Number value + const value = +this.keyboardType; + if (typeof this.keyboardType !== 'boolean' && !isNaN(value)) { + this._setInputType(value); + return; + } - // Check for a passed in numeric value - if (typeof this.keyboardType !== 'boolean' && !isNaN(numericKeyboardType)) { - inputType = numericKeyboardType; - } else if (this.secure) { - // Password variations are supported only for Text and Number classes + // Password variations are supported only for Text and Number classes. + if (this.secure) { if (this.keyboardType === 'number') { inputType = android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_VARIATION_PASSWORD; } else { inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD; } - - this._pendingTransformationMethod = nativeView.getTransformationMethod(); } else { - // Default + // default inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_NORMAL; - // Add autocorrect flags + // add autocorrect flags if (this.autocorrect) { inputType = inputType | android.text.InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE; inputType = inputType | android.text.InputType.TYPE_TEXT_FLAG_AUTO_CORRECT; inputType = inputType & ~android.text.InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS; } - // Add autocapitalization type + // add autocapitalization type switch (this.autocapitalizationType) { case 'words': inputType = inputType | android.text.InputType.TYPE_TEXT_FLAG_CAP_WORDS; //8192 (0x00020000) 14th bit @@ -81,7 +68,8 @@ export class TextField extends TextFieldBase { break; } - // Add keyboardType flags (they override previous if set) + // add keyboardType flags. + // They override previous if set. switch (this.keyboardType) { case 'datetime': inputType = android.text.InputType.TYPE_CLASS_DATETIME | android.text.InputType.TYPE_DATETIME_VARIATION_NORMAL; @@ -107,23 +95,6 @@ export class TextField extends TextFieldBase { } this._setInputType(inputType); - - // Restore text transformation when secure is set back to false - // This also takes care of transformation issues when toggling secure while view is not editable - if (!this.secure && this._pendingTransformationMethod) { - if (this._pendingTransformationMethod != nativeView.getTransformationMethod()) { - nativeView.setTransformationMethod(this._pendingTransformationMethod); - } - this._pendingTransformationMethod = null; - } - } - - [secureProperty.setNative]() { - this.setSecureAndKeyboardType(); - } - - [keyboardTypeProperty.setNative]() { - this.setSecureAndKeyboardType(); } [whiteSpaceProperty.getDefault](): CoreTypes.WhiteSpaceType {