revert: "fix(android): proper change of input interaction mode programmatically (#10434) (#10512)

This reverts commit 07d2129f9c9b387c238c9a7c2da29b5690bac986.
This commit is contained in:
Dimitris-Rafail Katsampas
2024-04-15 03:07:25 +03:00
committed by GitHub
parent 2b0f2678ba
commit 873f711a6b
7 changed files with 39 additions and 106 deletions

View File

@ -1,6 +1,5 @@
import { EditableTextBase as EditableTextBaseCommon, autofillTypeProperty, keyboardTypeProperty, returnKeyTypeProperty, editableProperty, autocapitalizationTypeProperty, autocorrectProperty, hintProperty, placeholderColorProperty, maxLengthProperty } from './editable-text-base-common'; 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 { textTransformProperty, textProperty, resetSymbol } from '../text-base';
import { isUserInteractionEnabledProperty } from '../core/view';
import { Color } from '../../color'; import { Color } from '../../color';
import { ad } from '../../utils'; import { ad } from '../../utils';
import { SDK_VERSION } from '../../utils/constants'; import { SDK_VERSION } from '../../utils/constants';
@ -178,8 +177,13 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
this._keyListenerCache = listener; 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) { 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) { if (value) {
nativeView.setKeyListener(this._keyListenerCache); nativeView.setKeyListener(this._keyListenerCache);
} else { } else {
// Dismiss input if property changes to false programmatically or user will keep typing
this.dismissSoftInput();
if (!this._keyListenerCache) { if (!this._keyListenerCache) {
this._keyListenerCache = nativeView.getKeyListener(); 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) { public setSelection(start: number, stop?: number) {
const view = this.nativeTextViewProtected; const view = this.nativeTextViewProtected;
if (view) { if (view) {

View File

@ -1,7 +1,7 @@
import { ScrollEventData } from '.'; import { ScrollEventData } from '.';
import { ScrollViewBase, scrollBarIndicatorVisibleProperty, isScrollEnabledProperty } from './scroll-view-common'; import { ScrollViewBase, scrollBarIndicatorVisibleProperty, isScrollEnabledProperty } from './scroll-view-common';
import { isUserInteractionEnabledProperty } from '../core/view';
import { layout } from '../../utils'; import { layout } from '../../utils';
import { isUserInteractionEnabledProperty } from '../core/view';
export * from './scroll-view-common'; export * from './scroll-view-common';

View File

@ -1,9 +1,9 @@
import { Font } from '../styling/font'; import { Font } from '../styling/font';
import { SearchBarBase, textProperty, hintProperty, textFieldHintColorProperty, textFieldBackgroundColorProperty } from './search-bar-common'; import { SearchBarBase, textProperty, hintProperty, textFieldHintColorProperty, textFieldBackgroundColorProperty } from './search-bar-common';
import { isUserInteractionEnabledProperty, isEnabledProperty } from '../core/view'; import { isUserInteractionEnabledProperty, isEnabledProperty } from '../core/view';
import { colorProperty, backgroundColorProperty, backgroundInternalProperty, fontInternalProperty, fontSizeProperty } from '../styling/style-properties';
import { ad } from '../../utils'; import { ad } from '../../utils';
import { Color } from '../../color'; import { Color } from '../../color';
import { colorProperty, backgroundColorProperty, backgroundInternalProperty, fontInternalProperty, fontSizeProperty } from '../styling/style-properties';
export * from './search-bar-common'; export * from './search-bar-common';
@ -97,19 +97,6 @@ function enableSearchView(nativeView: any, value: boolean) {
} }
function enableUserInteractionSearchView(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.setClickable(value);
nativeView.setFocusable(value); nativeView.setFocusable(value);

View File

@ -223,18 +223,6 @@ export class TextBase extends TextBaseCommon {
this._maxHeight = this._maxLines = undefined; 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 { [textProperty.getDefault](): symbol | number {
return resetSymbol; return resetSymbol;
} }
@ -249,11 +237,12 @@ export class TextBase extends TextBaseCommon {
this._setNativeText(reset); this._setNativeText(reset);
} }
[textStrokeProperty.setNative](value: StrokeCSSValues) { [textStrokeProperty.setNative](value: StrokeCSSValues) {
this._setNativeText(); this._setNativeText();
} }
createFormattedTextNative(value: FormattedString) {
return createSpannableStringBuilder(value, this.style.fontSize);
}
[formattedTextProperty.setNative](value: FormattedString) { [formattedTextProperty.setNative](value: FormattedString) {
const nativeView = this.nativeTextViewProtected; const nativeView = this.nativeTextViewProtected;
if (!value) { if (!value) {
@ -282,10 +271,18 @@ export class TextBase extends TextBaseCommon {
} }
[textTransformProperty.setNative](value: CoreTypes.TextTransformType) { [textTransformProperty.setNative](value: CoreTypes.TextTransformType) {
const transformationMethod = this._getNativeTextTransform(value); if (value === 'initial') {
if (transformationMethod != null) { this.nativeTextViewProtected.setTransformationMethod(this._defaultTransformationMethod);
this.nativeTextViewProtected.setTransformationMethod(transformationMethod);
return;
} }
// Don't change the transformation method if this is secure TextField or we'll lose the hiding characters.
if ((<any>this).secure) {
return;
}
this.nativeTextViewProtected.setTransformationMethod(new TextTransformation(this));
} }
[textAlignmentProperty.getDefault](): CoreTypes.TextAlignmentType { [textAlignmentProperty.getDefault](): CoreTypes.TextAlignmentType {

View File

@ -130,11 +130,6 @@ export class TextBase extends View implements AddChildFromBuilder {
*/ */
_setNativeText(reset?: boolean): void; _setNativeText(reset?: boolean): void;
/**
* @private
*/
_getNativeTextTransform(value: CoreTypes.TextTransformType): android.text.method.TransformationMethod;
/** /**
* @private * @private
*/ */

View File

@ -212,10 +212,6 @@ export abstract class TextBaseCommon extends View implements TextBaseDefinition
_setNativeText(reset = false): void { _setNativeText(reset = false): void {
// //
} }
_getNativeTextTransform(value: CoreTypes.TextTransformType): any {
//
}
} }
TextBaseCommon.prototype._isSingleLine = false; TextBaseCommon.prototype._isSingleLine = false;

View File

@ -6,10 +6,6 @@ import { CoreTypes } from '../../core-types';
export * from './text-field-common'; export * from './text-field-common';
export class TextField extends TextFieldBase { export class TextField extends TextFieldBase {
nativeViewProtected: android.widget.EditText;
private _pendingTransformationMethod: android.text.method.TransformationMethod;
public _configureEditText(editText: android.widget.EditText) { 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.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); editText.setLines(1);
@ -21,52 +17,43 @@ export class TextField extends TextFieldBase {
this.notify({ eventName: TextField.returnPressEvent, object: this }); this.notify({ eventName: TextField.returnPressEvent, object: this });
} }
public disposeNativeView(): void { [secureProperty.setNative]() {
this._pendingTransformationMethod = null; this.setSecureAndKeyboardType();
super.disposeNativeView();
} }
_getNativeTextTransform(value: CoreTypes.TextTransformType): android.text.method.TransformationMethod { [keyboardTypeProperty.setNative]() {
const transformationMethod = super._getNativeTextTransform(value); this.setSecureAndKeyboardType();
if (this.secure) {
this._pendingTransformationMethod = transformationMethod;
return null;
}
return transformationMethod;
} }
setSecureAndKeyboardType(): void { setSecureAndKeyboardType(): void {
let inputType: number; let inputType: number;
const nativeView = this.nativeTextViewProtected; // Check for a passed in Number value
const numericKeyboardType = +this.keyboardType; const value = +this.keyboardType;
if (typeof this.keyboardType !== 'boolean' && !isNaN(value)) {
this._setInputType(value);
return;
}
// Check for a passed in numeric value // Password variations are supported only for Text and Number classes.
if (typeof this.keyboardType !== 'boolean' && !isNaN(numericKeyboardType)) { if (this.secure) {
inputType = numericKeyboardType;
} else if (this.secure) {
// Password variations are supported only for Text and Number classes
if (this.keyboardType === 'number') { if (this.keyboardType === 'number') {
inputType = android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_VARIATION_PASSWORD; inputType = android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_VARIATION_PASSWORD;
} else { } else {
inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD; inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD;
} }
this._pendingTransformationMethod = nativeView.getTransformationMethod();
} else { } else {
// Default // default
inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_NORMAL; inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_NORMAL;
// Add autocorrect flags // add autocorrect flags
if (this.autocorrect) { if (this.autocorrect) {
inputType = inputType | android.text.InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE; 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_AUTO_CORRECT;
inputType = inputType & ~android.text.InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS; inputType = inputType & ~android.text.InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
} }
// Add autocapitalization type // add autocapitalization type
switch (this.autocapitalizationType) { switch (this.autocapitalizationType) {
case 'words': case 'words':
inputType = inputType | android.text.InputType.TYPE_TEXT_FLAG_CAP_WORDS; //8192 (0x00020000) 14th bit inputType = inputType | android.text.InputType.TYPE_TEXT_FLAG_CAP_WORDS; //8192 (0x00020000) 14th bit
@ -81,7 +68,8 @@ export class TextField extends TextFieldBase {
break; break;
} }
// Add keyboardType flags (they override previous if set) // add keyboardType flags.
// They override previous if set.
switch (this.keyboardType) { switch (this.keyboardType) {
case 'datetime': case 'datetime':
inputType = android.text.InputType.TYPE_CLASS_DATETIME | android.text.InputType.TYPE_DATETIME_VARIATION_NORMAL; 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); 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 { [whiteSpaceProperty.getDefault](): CoreTypes.WhiteSpaceType {