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 { 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) {

View File

@ -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';

View File

@ -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);

View File

@ -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 ((<any>this).secure) {
return;
}
this.nativeTextViewProtected.setTransformationMethod(new TextTransformation(this));
}
[textAlignmentProperty.getDefault](): CoreTypes.TextAlignmentType {

View File

@ -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
*/

View File

@ -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;

View File

@ -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 {