Skip to content

Commit

Permalink
Back out "1/2 TextInput accessibilityErrorMessage (Talkback, Android)"
Browse files Browse the repository at this point in the history
Summary:
This diff is reverting PR #33468

Due to an increase of java.lang.IllegalStateException caused by the PR

Original commit changeset: cd80e9a1be8f

Original Phabricator Diff: D38410635

Changelog:
[Android][Fixed] - removed logic that calls the [AccessibilityNodeInfo#setError][10] and [#setContentInvalid][13] method to display the error message in the TextInput - Revert of PR #33468

Reviewed By: NickGerleman, makovkastar

Differential Revision: D44032331

fbshipit-source-id: 732ed0cf23e4f30ae00c51dace851a3fdfe65c01
  • Loading branch information
mdvacca authored and facebook-github-bot committed Mar 14, 2023
1 parent 21d5302 commit ca0d565
Show file tree
Hide file tree
Showing 16 changed files with 10 additions and 280 deletions.
10 changes: 0 additions & 10 deletions Libraries/Components/TextInput/AndroidTextInputNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,6 @@ export type NativeProps = $ReadOnly<{|
'off',
>,

/**
* String to be read by screenreaders to indicate an error state. The acceptable parameters
* of accessibilityErrorMessage is a string. Setting accessibilityInvalid to true activates
* the error message. Setting accessibilityInvalid to false removes the error message.
*/
accessibilityErrorMessage?: ?Stringish,
accessibilityInvalid?: ?boolean,

/**
* Sets the return key to the label. Use it instead of `returnKeyType`.
* @platform android
Expand Down Expand Up @@ -738,8 +730,6 @@ export const __INTERNAL_VIEW_CONFIG: PartialViewConfig = {
inlineImageLeft: true,
editable: true,
fontVariant: true,
accessibilityErrorMessage: true,
accessibilityInvalid: true,
borderBottomRightRadius: true,
borderBottomColor: {
process: require('../../StyleSheet/processColor').default,
Expand Down
8 changes: 0 additions & 8 deletions Libraries/Components/TextInput/TextInput.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,14 +531,6 @@ export interface TextInputProps
TextInputIOSProps,
TextInputAndroidProps,
AccessibilityProps {
/**
* String to be read by screenreaders to indicate an error state. The acceptable parameters
* of accessibilityErrorMessage is a string. Setting accessibilityInvalid to true activates
* the error message. Setting accessibilityInvalid to false removes the error message.
*/
accessibilityErrorMessage?: string | undefined;
accessibilityInvalid?: boolean | undefined;

/**
* Specifies whether fonts should scale to respect Text Size accessibility settings.
* The default is `true`.
Expand Down
8 changes: 0 additions & 8 deletions Libraries/Components/TextInput/TextInput.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,14 +523,6 @@ export type Props = $ReadOnly<{|
...IOSProps,
...AndroidProps,

/**
* String to be read by screenreaders to indicate an error state. The acceptable parameters
* of accessibilityErrorMessage is a string. Setting accessibilityInvalid to true activates
* the error message. Setting accessibilityInvalid to false removes the error message.
*/
accessibilityErrorMessage?: ?Stringish,
accessibilityInvalid?: ?boolean,

/**
* Can tell `TextInput` to automatically capitalize certain characters.
*
Expand Down
16 changes: 0 additions & 16 deletions Libraries/Components/TextInput/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,14 +561,6 @@ export type Props = $ReadOnly<{|
...IOSProps,
...AndroidProps,

/**
* String to be read by screenreaders to indicate an error state. The acceptable parameters
* of accessibilityErrorMessage is a string. Setting accessibilityInvalid to true activates
* the error message. Setting accessibilityInvalid to false removes the error message.
*/
accessibilityErrorMessage?: ?Stringish,
accessibilityInvalid?: ?boolean,

/**
* Can tell `TextInput` to automatically capitalize certain characters.
*
Expand Down Expand Up @@ -1373,12 +1365,6 @@ function InternalTextInput(props: Props): React.Node {
}

const accessible = props.accessible !== false;

const accessibilityErrorMessage =
props.accessibilityInvalid === true
? props.accessibilityErrorMessage
: null;

const focusable = props.focusable !== false;

const config = React.useMemo(
Expand Down Expand Up @@ -1453,7 +1439,6 @@ function InternalTextInput(props: Props): React.Node {
ref={ref}
{...otherProps}
{...eventHandlers}
accessibilityErrorMessage={accessibilityErrorMessage}
accessibilityState={_accessibilityState}
accessible={accessible}
submitBehavior={submitBehavior}
Expand Down Expand Up @@ -1505,7 +1490,6 @@ function InternalTextInput(props: Props): React.Node {
ref={ref}
{...otherProps}
{...eventHandlers}
accessibilityErrorMessage={accessibilityErrorMessage}
accessibilityState={_accessibilityState}
accessibilityLabelledBy={_accessibilityLabelledBy}
accessible={accessible}
Expand Down
4 changes: 0 additions & 4 deletions Libraries/Components/TextInput/__tests__/TextInput-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ describe('TextInput', () => {

expect(instance.toJSON()).toMatchInlineSnapshot(`
<RCTSinglelineTextInputView
accessibilityErrorMessage={null}
accessible={true}
allowFontScaling={true}
focusable={true}
Expand Down Expand Up @@ -232,7 +231,6 @@ describe('TextInput compat with web', () => {

expect(instance.toJSON()).toMatchInlineSnapshot(`
<RCTSinglelineTextInputView
accessibilityErrorMessage={null}
accessible={true}
allowFontScaling={true}
focusable={true}
Expand Down Expand Up @@ -317,7 +315,6 @@ describe('TextInput compat with web', () => {

expect(instance.toJSON()).toMatchInlineSnapshot(`
<RCTSinglelineTextInputView
accessibilityErrorMessage={null}
accessibilityState={
Object {
"busy": true,
Expand Down Expand Up @@ -409,7 +406,6 @@ describe('TextInput compat with web', () => {

expect(instance.toJSON()).toMatchInlineSnapshot(`
<RCTSinglelineTextInputView
accessibilityErrorMessage={null}
accessible={true}
allowFontScaling={true}
focusable={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

exports[`TextInput tests should render as expected: should deep render when mocked (please verify output manually) 1`] = `
<RCTSinglelineTextInputView
accessibilityErrorMessage={null}
accessible={true}
allowFontScaling={true}
focusable={true}
Expand Down Expand Up @@ -32,7 +31,6 @@ exports[`TextInput tests should render as expected: should deep render when mock

exports[`TextInput tests should render as expected: should deep render when not mocked (please verify output manually) 1`] = `
<RCTSinglelineTextInputView
accessibilityErrorMessage={null}
accessible={true}
allowFontScaling={true}
focusable={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,6 @@ public void setAccessibilityRole(@NonNull T view, @Nullable String accessibility
view.setTag(R.id.accessibility_role, AccessibilityRole.fromValue(accessibilityRole));
}

@ReactProp(name = "accessibilityErrorMessage")
public void setScreenreaderError(@NonNull T view, @Nullable String accessibilityErrorMessage) {
view.setTag(R.id.accessibility_error_message, accessibilityErrorMessage);
}

@Override
@ReactProp(name = ViewProps.ACCESSIBILITY_COLLECTION)
public void setAccessibilityCollection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import android.text.Layout;
import android.text.Spannable;
import androidx.annotation.Nullable;

/**
* Class that contains the data needed for a text update. Used by both <Text/> and <TextInput/>
Expand All @@ -31,7 +30,6 @@ public class ReactTextUpdate {
private final int mSelectionStart;
private final int mSelectionEnd;
private final int mJustificationMode;
private @Nullable String mAccessibilityErrorMessage;

public boolean mContainsMultipleFragments;

Expand Down Expand Up @@ -61,8 +59,7 @@ public ReactTextUpdate(
Layout.BREAK_STRATEGY_HIGH_QUALITY,
Layout.JUSTIFICATION_MODE_NONE,
-1,
-1,
null);
-1);
}

public ReactTextUpdate(
Expand All @@ -88,8 +85,7 @@ public ReactTextUpdate(
textBreakStrategy,
justificationMode,
-1,
-1,
null);
-1);
}

public ReactTextUpdate(
Expand All @@ -111,8 +107,7 @@ public ReactTextUpdate(
textBreakStrategy,
justificationMode,
-1,
-1,
null);
-1);
}

public ReactTextUpdate(
Expand Down Expand Up @@ -142,56 +137,21 @@ public ReactTextUpdate(
mJustificationMode = justificationMode;
}

public ReactTextUpdate(
Spannable text,
int jsEventCounter,
boolean containsImages,
float paddingStart,
float paddingTop,
float paddingEnd,
float paddingBottom,
int textAlign,
int textBreakStrategy,
int justificationMode,
int selectionStart,
int selectionEnd,
@Nullable String accessibilityErrorMessage) {
mText = text;
mJsEventCounter = jsEventCounter;
mContainsImages = containsImages;
mPaddingLeft = paddingStart;
mPaddingTop = paddingTop;
mPaddingRight = paddingEnd;
mPaddingBottom = paddingBottom;
mTextAlign = textAlign;
mTextBreakStrategy = textBreakStrategy;
mSelectionStart = selectionStart;
mSelectionEnd = selectionEnd;
mJustificationMode = justificationMode;
mAccessibilityErrorMessage = accessibilityErrorMessage;
}

public static ReactTextUpdate buildReactTextUpdateFromState(
Spannable text,
int jsEventCounter,
int textAlign,
int textBreakStrategy,
int justificationMode,
boolean containsMultipleFragments,
@Nullable String accessibilityErrorMessage) {
boolean containsMultipleFragments) {

ReactTextUpdate reactTextUpdate =
new ReactTextUpdate(
text, jsEventCounter, false, textAlign, textBreakStrategy, justificationMode);
reactTextUpdate.mContainsMultipleFragments = containsMultipleFragments;
reactTextUpdate.mAccessibilityErrorMessage = accessibilityErrorMessage;
return reactTextUpdate;
}

public @Nullable String getScreenreaderError() {
return mAccessibilityErrorMessage;
}

public Spannable getText() {
return mText;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ rn_android_library(
react_native_target("java/com/facebook/react/common/mapbuffer:mapbuffer"),
react_native_target("java/com/facebook/react/views/view:view"),
react_native_target("java/com/facebook/react/config:config"),
react_native_target("res:uimanager"),
] + KOTLIN_STDLIB_DEPS,
exported_deps = [
react_native_dep("third-party/android/androidx:appcompat"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,15 @@
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatEditText;
import androidx.core.view.ViewCompat;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import com.facebook.common.logging.FLog;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.R;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactSoftExceptionLogger;
import com.facebook.react.common.build.ReactBuildConfig;
Expand Down Expand Up @@ -160,36 +157,6 @@ public ReactEditText(Context context) {
ReactAccessibilityDelegate editTextAccessibilityDelegate =
new ReactAccessibilityDelegate(
this, this.isFocusable(), this.getImportantForAccessibility()) {
@Override
public void onInitializeAccessibilityNodeInfo(
View host, AccessibilityNodeInfoCompat info) {
super.onInitializeAccessibilityNodeInfo(host, info);
final String accessibilityErrorMessage =
(String) host.getTag(R.id.accessibility_error_message);
boolean contentInvalid = accessibilityErrorMessage == null ? false : true;
if (accessibilityErrorMessage != info.getError()) {
info.setError(accessibilityErrorMessage);
info.setContentInvalid(contentInvalid);
}
}

@Override
public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
super.onInitializeAccessibilityEvent(host, event);
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED
&& host.getParent() != null) {
try {
host.getParent().requestSendAccessibilityEvent(host, event);
} catch (AbstractMethodError e) {
FLog.w(
TAG,
host.getParent().getClass().getSimpleName()
+ " does not fully implement ViewParent",
e);
}
}
}

@Override
public boolean performAccessibilityAction(View host, int action, Bundle args) {
if (action == AccessibilityNodeInfo.ACTION_CLICK) {
Expand Down Expand Up @@ -572,25 +539,6 @@ public int incrementAndGetEventCounter() {
return ++mNativeEventCount;
}

/**
* Attempt to set an accessibility error or fail silently. EventCounter is the same one used as
* with text.
*
* @param eventCounter
* @param accessibilityErrorMessage
*/
public void maybeSetAccessibilityError(
int eventCounter, @Nullable String accessibilityErrorMessage) {
String previousScreenreaderError = (String) getTag(R.id.accessibility_error_message);
if (!canUpdateWithEventCount(eventCounter)
|| previousScreenreaderError == accessibilityErrorMessage) {
return;
}

setTag(R.id.accessibility_error_message, accessibilityErrorMessage);
sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
}

public void maybeSetTextFromJS(ReactTextUpdate reactTextUpdate) {
mIsSettingTextFromJS = true;
maybeSetText(reactTextUpdate);
Expand Down
Loading

0 comments on commit ca0d565

Please sign in to comment.