From 429ab0dfc0a8a6672fcc3b7791daea12c99be272 Mon Sep 17 00:00:00 2001 From: williamdeng Date: Mon, 20 Apr 2020 23:19:20 +0800 Subject: [PATCH] f70e58f3559b2f22c41ed867940dcfe170955548|Facebook Github Bot|- remove accessibilityComponentType and accessibilityTraits props (a11y) (#24344) --- .../Touchable/TouchableWithoutFeedback.js | 19 +-- .../View/ReactNativeViewAttributes.js | 2 - .../Components/View/ViewAccessibility.js | 29 ---- Libraries/Components/View/ViewPropTypes.js | 86 +--------- .../DeprecatedViewAccessibility.js | 25 --- .../DeprecatedViewPropTypes.js | 29 ---- React/Views/RCTViewManager.m | 11 -- .../react/uimanager/AccessibilityHelper.java | 157 ------------------ .../react/uimanager/BaseViewManager.java | 6 - .../uimanager/NativeViewHierarchyManager.java | 2 +- 10 files changed, 12 insertions(+), 354 deletions(-) delete mode 100644 ReactAndroid/src/main/java/com/facebook/react/uimanager/AccessibilityHelper.java diff --git a/Libraries/Components/Touchable/TouchableWithoutFeedback.js b/Libraries/Components/Touchable/TouchableWithoutFeedback.js index f4abd63d9bf580..ec8b419a2c0144 100755 --- a/Libraries/Components/Touchable/TouchableWithoutFeedback.js +++ b/Libraries/Components/Touchable/TouchableWithoutFeedback.js @@ -21,27 +21,19 @@ const createReactClass = require('create-react-class'); const ensurePositiveDelayProps = require('ensurePositiveDelayProps'); const { - DeprecatedAccessibilityComponentTypes, DeprecatedAccessibilityRoles, DeprecatedAccessibilityStates, - DeprecatedAccessibilityTraits, } = require('DeprecatedViewAccessibility'); export type Event = Object; import type {EdgeInsetsProp} from 'EdgeInsetsPropType'; -import type { - AccessibilityComponentType, - AccessibilityRole, - AccessibilityStates, - AccessibilityTraits, -} from 'ViewAccessibility'; +import type {AccessibilityRole, AccessibilityStates} from 'ViewAccessibility'; const PRESS_RETENTION_OFFSET = {top: 20, left: 20, right: 20, bottom: 30}; export type Props = $ReadOnly<{| accessible?: ?boolean, - accessibilityComponentType?: ?AccessibilityComponentType, accessibilityLabel?: | null | React$PropType$Primitive @@ -51,7 +43,6 @@ export type Props = $ReadOnly<{| accessibilityIgnoresInvertColors?: ?boolean, accessibilityRole?: ?AccessibilityRole, accessibilityStates?: ?AccessibilityStates, - accessibilityTraits?: ?AccessibilityTraits, children?: ?React.Node, delayLongPress?: ?number, delayPressIn?: ?number, @@ -83,17 +74,11 @@ const TouchableWithoutFeedback = ((createReactClass({ propTypes: { accessible: PropTypes.bool, accessibilityLabel: PropTypes.node, - accessibilityComponentType: PropTypes.oneOf( - DeprecatedAccessibilityComponentTypes, - ), + accessibilityIgnoresInvertColors: PropTypes.bool, accessibilityRole: PropTypes.oneOf(DeprecatedAccessibilityRoles), accessibilityStates: PropTypes.arrayOf( PropTypes.oneOf(DeprecatedAccessibilityStates), ), - accessibilityTraits: PropTypes.oneOfType([ - PropTypes.oneOf(DeprecatedAccessibilityTraits), - PropTypes.arrayOf(PropTypes.oneOf(DeprecatedAccessibilityTraits)), - ]), /** * If true, disable all interactions for this component. */ diff --git a/Libraries/Components/View/ReactNativeViewAttributes.js b/Libraries/Components/View/ReactNativeViewAttributes.js index 22f5a38839a5a0..ec7e6c846fe3c3 100644 --- a/Libraries/Components/View/ReactNativeViewAttributes.js +++ b/Libraries/Components/View/ReactNativeViewAttributes.js @@ -20,11 +20,9 @@ ReactNativeViewAttributes.UIView = { accessible: true, accessibilityActions: true, accessibilityLabel: true, - accessibilityComponentType: true, accessibilityLiveRegion: true, accessibilityRole: true, accessibilityStates: true, - accessibilityTraits: true, importantForAccessibility: true, nativeID: true, testID: true, diff --git a/Libraries/Components/View/ViewAccessibility.js b/Libraries/Components/View/ViewAccessibility.js index 2b7195236cb607..23336a8cd76ba6 100644 --- a/Libraries/Components/View/ViewAccessibility.js +++ b/Libraries/Components/View/ViewAccessibility.js @@ -11,35 +11,6 @@ */ 'use strict'; -export type AccessibilityTrait = - | 'none' - | 'button' - | 'link' - | 'header' - | 'search' - | 'image' - | 'selected' - | 'plays' - | 'key' - | 'text' - | 'summary' - | 'disabled' - | 'frequentUpdates' - | 'startsMedia' - | 'adjustable' - | 'allowsDirectInteraction' - | 'pageTurn'; - -export type AccessibilityTraits = - | AccessibilityTrait - | $ReadOnlyArray; - -export type AccessibilityComponentType = - | 'none' - | 'button' - | 'radiobutton_checked' - | 'radiobutton_unchecked'; - // This must be kept in sync with the AccessibilityRolesMask in RCTViewManager.m export type AccessibilityRole = | 'none' diff --git a/Libraries/Components/View/ViewPropTypes.js b/Libraries/Components/View/ViewPropTypes.js index 5ec67d717d5718..91d20e57c3e4bf 100644 --- a/Libraries/Components/View/ViewPropTypes.js +++ b/Libraries/Components/View/ViewPropTypes.js @@ -17,18 +17,11 @@ const StyleSheetPropType = require('StyleSheetPropType'); const ViewStylePropTypes = require('ViewStylePropTypes'); const { - AccessibilityComponentTypes, - AccessibilityTraits, - AccessibilityRoles, - AccessibilityStates, -} = require('ViewAccessibility'); - -import type { - AccessibilityComponentType, - AccessibilityTrait, - AccessibilityRole, - AccessibilityState, -} from 'ViewAccessibility'; + DeprecatedAccessibilityRoles, + DeprecatedAccessibilityStates, +} = require('DeprecatedViewAccessibility'); + +import type {AccessibilityRole, AccessibilityStates} from 'ViewAccessibility'; import type {EdgeInsetsProp} from 'EdgeInsetsPropType'; import type {TVViewProps} from 'TVViewPropTypes'; @@ -58,13 +51,11 @@ export type ViewProps = { | Array | any, accessibilityActions?: Array, - accessibilityComponentType?: AccessibilityComponentType, accessibilityLiveRegion?: 'none' | 'polite' | 'assertive', importantForAccessibility?: 'auto'| 'yes'| 'no'| 'no-hide-descendants', accessibilityIgnoresInvertColors?: boolean, - accessibilityTraits?: AccessibilityTrait | Array, - accessibilityRole?: AccessibilityRole, - accessibilityStates?: Array, + accessibilityRole?: ?AccessibilityRole, + accessibilityStates?: ?AccessibilityStates, accessibilityViewIsModal?: bool, onAccessibilityAction?: Function, onAccessibilityTap?: Function, @@ -122,38 +113,15 @@ module.exports = { */ accessibilityIgnoresInvertColors: PropTypes.bool, - /** - * Indicates to accessibility services to treat UI component like a - * native one. Works for Android only. - * - * Possible values are one of: - * - * - `'none'` - * - `'button'` - * - `'checkbox'` - * - `'radiobutton'` - * - `'switch'` - * - `'checked'` - * - `'disabled'` - * - `'radiobutton_checked'` (deprecated) - * - `'radiobutton_unchecked'` (deprecated) - * - * @platform android - */ - accessibilityComponentType: PropTypes.oneOfType([ - PropTypes.oneOf(AccessibilityComponentTypes), - PropTypes.arrayOf(PropTypes.oneOf(AccessibilityComponentTypes)), - ]), - /** * Indicates to accessibility services to treat UI component like a specific role. */ - accessibilityRole: PropTypes.oneOf(AccessibilityRoles), + accessibilityRole: PropTypes.oneOf(DeprecatedAccessibilityRoles), /** * Indicates to accessibility services that UI Component is in a specific State. */ - accessibilityStates: PropTypes.arrayOf(PropTypes.oneOf(AccessibilityStates)), + accessibilityStates: PropTypes.arrayOf(PropTypes.oneOf(DeprecatedAccessibilityStates)), /** * Indicates to accessibility services whether the user should be notified @@ -201,42 +169,6 @@ module.exports = { 'no-hide-descendants', ]), - /** - * Provides additional traits to screen reader. By default no traits are - * provided unless specified otherwise in element. - * - * You can provide one trait or an array of many traits. - * - * Possible values for `AccessibilityTraits` are: - * - * - `'none'` - The element has no traits. - * - `'button'` - The element should be treated as a button. - * - `'link'` - The element should be treated as a link. - * - `'header'` - The element is a header that divides content into sections. - * - `'search'` - The element should be treated as a search field. - * - `'image'` - The element should be treated as an image. - * - `'selected'` - The element is selected. - * - `'plays'` - The element plays sound. - * - `'key'` - The element should be treated like a keyboard key. - * - `'text'` - The element should be treated as text. - * - `'summary'` - The element provides app summary information. - * - `'disabled'` - The element is disabled. - * - `'frequentUpdates'` - The element frequently changes its value. - * - `'startsMedia'` - The element starts a media session. - * - `'adjustable'` - The element allows adjustment over a range of values. - * - `'allowsDirectInteraction'` - The element allows direct touch interaction for VoiceOver users. - * - `'pageTurn'` - Informs VoiceOver that it should scroll to the next page when it finishes reading the contents of the element. - * - * See the [Accessibility guide](docs/accessibility.html#accessibilitytraits-ios) - * for more information. - * - * @platform ios - */ - accessibilityTraits: PropTypes.oneOfType([ - PropTypes.oneOf(AccessibilityTraits), - PropTypes.arrayOf(PropTypes.oneOf(AccessibilityTraits)), - ]), - /** * A value indicating whether VoiceOver should ignore the elements * within views that are siblings of the receiver. diff --git a/Libraries/DeprecatedPropTypes/DeprecatedViewAccessibility.js b/Libraries/DeprecatedPropTypes/DeprecatedViewAccessibility.js index 890dd49f0f8672..5b5c8a8164757b 100644 --- a/Libraries/DeprecatedPropTypes/DeprecatedViewAccessibility.js +++ b/Libraries/DeprecatedPropTypes/DeprecatedViewAccessibility.js @@ -11,31 +11,6 @@ 'use strict'; module.exports = { - DeprecatedAccessibilityTraits: [ - 'none', - 'button', - 'link', - 'header', - 'search', - 'image', - 'selected', - 'plays', - 'key', - 'text', - 'summary', - 'disabled', - 'frequentUpdates', - 'startsMedia', - 'adjustable', - 'allowsDirectInteraction', - 'pageTurn', - ], - DeprecatedAccessibilityComponentTypes: [ - 'none', - 'button', - 'radiobutton_checked', - 'radiobutton_unchecked', - ], // This must be kept in sync with the AccessibilityRolesMask in RCTViewManager.m DeprecatedAccessibilityRoles: [ 'none', diff --git a/Libraries/DeprecatedPropTypes/DeprecatedViewPropTypes.js b/Libraries/DeprecatedPropTypes/DeprecatedViewPropTypes.js index 5b95219f67f71b..83bdd7c076e5e4 100644 --- a/Libraries/DeprecatedPropTypes/DeprecatedViewPropTypes.js +++ b/Libraries/DeprecatedPropTypes/DeprecatedViewPropTypes.js @@ -17,8 +17,6 @@ const DeprecatedStyleSheetPropType = require('DeprecatedStyleSheetPropType'); const DeprecatedViewStylePropTypes = require('DeprecatedViewStylePropTypes'); const { - DeprecatedAccessibilityComponentTypes, - DeprecatedAccessibilityTraits, DeprecatedAccessibilityRoles, DeprecatedAccessibilityStates, } = require('DeprecatedViewAccessibility'); @@ -59,18 +57,6 @@ module.exports = { */ accessibilityIgnoresInvertColors: PropTypes.bool, - /** - * Indicates to accessibility services to treat UI component like a - * native one. Works for Android only. - * - * @platform android - * - * See http://facebook.github.io/react-native/docs/view.html#accessibilitycomponenttype - */ - accessibilityComponentType: PropTypes.oneOf( - DeprecatedAccessibilityComponentTypes, - ), - /** * Indicates to accessibility services to treat UI component like a specific role. */ @@ -108,21 +94,6 @@ module.exports = { 'no-hide-descendants', ]), - /** - * Provides additional traits to screen reader. By default no traits are - * provided unless specified otherwise in element. - * - * You can provide one trait or an array of many traits. - * - * @platform ios - * - * See http://facebook.github.io/react-native/docs/view.html#accessibilitytraits - */ - accessibilityTraits: PropTypes.oneOfType([ - PropTypes.oneOf(DeprecatedAccessibilityTraits), - PropTypes.arrayOf(PropTypes.oneOf(DeprecatedAccessibilityTraits)), - ]), - /** * A value indicating whether VoiceOver should ignore the elements * within views that are siblings of the receiver. diff --git a/React/Views/RCTViewManager.m b/React/Views/RCTViewManager.m index d99a38e2286ccf..9d12c63a28934d 100644 --- a/React/Views/RCTViewManager.m +++ b/React/Views/RCTViewManager.m @@ -123,7 +123,6 @@ - (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(__unused NSDictio RCT_REMAP_VIEW_PROPERTY(accessible, reactAccessibilityElement.isAccessibilityElement, BOOL) RCT_REMAP_VIEW_PROPERTY(accessibilityActions, reactAccessibilityElement.accessibilityActions, NSString) RCT_REMAP_VIEW_PROPERTY(accessibilityLabel, reactAccessibilityElement.accessibilityLabel, NSString) -RCT_REMAP_VIEW_PROPERTY(accessibilityTraits, reactAccessibilityElement.accessibilityTraits, UIAccessibilityTraits) RCT_REMAP_VIEW_PROPERTY(accessibilityViewIsModal, reactAccessibilityElement.accessibilityViewIsModal, BOOL) RCT_REMAP_VIEW_PROPERTY(accessibilityIgnoresInvertColors, reactAccessibilityElement.shouldAccessibilityIgnoresInvertColors, BOOL) RCT_REMAP_VIEW_PROPERTY(onAccessibilityAction, reactAccessibilityElement.onAccessibilityAction, RCTDirectEventBlock) @@ -169,16 +168,6 @@ - (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(__unused NSDictio view.reactAccessibilityElement.accessibilityTraits = (view.reactAccessibilityElement.accessibilityTraits & ~AccessibilityRolesMask) | maskedTraits; } -RCT_CUSTOM_VIEW_PROPERTY(accessibilityStates, UIAccessibilityTraits, RCTView) -{ - // This mask must be kept in sync with the AccessibilityStates enum defined in ViewAccessibility.js and DeprecatedViewAccessibility.js - const UIAccessibilityTraits AccessibilityStatesMask = UIAccessibilityTraitNotEnabled | UIAccessibilityTraitSelected; - - UIAccessibilityTraits newTraits = json ? [RCTConvert UIAccessibilityTraits:json] : defaultView.accessibilityTraits; - UIAccessibilityTraits maskedTraits = newTraits & AccessibilityStatesMask; - view.reactAccessibilityElement.accessibilityTraits = (view.reactAccessibilityElement.accessibilityTraits & ~AccessibilityStatesMask) | maskedTraits; -} - RCT_CUSTOM_VIEW_PROPERTY(pointerEvents, RCTPointerEvents, RCTView) { if ([view respondsToSelector:@selector(setPointerEvents:)]) { diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/AccessibilityHelper.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/AccessibilityHelper.java deleted file mode 100644 index bb652c3cad1332..00000000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/AccessibilityHelper.java +++ /dev/null @@ -1,157 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -package com.facebook.react.uimanager; - -import android.view.View; -import android.view.accessibility.AccessibilityEvent; -import android.view.accessibility.AccessibilityNodeInfo; -import android.widget.Button; -import android.widget.RadioButton; -import android.widget.CheckBox; -import android.widget.Switch; - -import com.facebook.react.bridge.Dynamic; -import com.facebook.react.bridge.ReadableArray; -import com.facebook.react.bridge.ReadableType; - -/** - * Helper class containing logic for setting accessibility View properties. - */ -/* package */ class AccessibilityHelper { - - static final String BUTTON = "button"; - static final String RADIOBUTTON = "radiobutton"; - static final String CHECKBOX = "checkbox"; - static final String SWITCH = "switch"; - static final String CHECKED = "checked"; - static final String DISABLED = "disabled"; - static final String RADIOBUTTON_CHECKED = "radiobutton_checked"; - static final String RADIOBUTTON_UNCHECKED = "radiobutton_unchecked"; - - public static void updateAccessibilityComponentType(View view, Dynamic dynamic) { - AccessibilityDelegate delegate = new AccessibilityDelegate(); - - if (dynamic.getType() == ReadableType.String) { - String prop = dynamic.asString(); - switch (prop) { - case RADIOBUTTON_CHECKED: - delegate.setComponentType(RADIOBUTTON); - delegate.setComponentType(CHECKED); - break; - case RADIOBUTTON_UNCHECKED: - delegate.setComponentType(RADIOBUTTON); - break; - default: - if (!delegate.setComponentType(prop)) { - delegate = null; - }; - break; - } - } else if (dynamic.getType() == ReadableType.Array) { - ReadableArray componentTypeArray = dynamic.asArray(); - - for (int i = 0; i < componentTypeArray.size(); i++) { - String componentType = componentTypeArray.getString(i); - if (!delegate.setComponentType(componentType)) { - delegate = null; - break; - }; - } - } else { - delegate = null; - } - - view.setAccessibilityDelegate(delegate); - } - - public static void sendAccessibilityEvent(View view, int eventType) { - view.sendAccessibilityEvent(eventType); - } -} - -class AccessibilityDelegate extends View.AccessibilityDelegate { - private static final int CHECKABLE = 1; - private static final int CHECKED = 2; - private static final int DISABLED = 4; - - private String className = null; - private int flags = 0; - - boolean setComponentType(String componentType) { - switch (componentType) { - case AccessibilityHelper.BUTTON: - className = Button.class.getName(); - break; - case AccessibilityHelper.RADIOBUTTON: - className = RadioButton.class.getName(); - setCheckable(); - break; - case AccessibilityHelper.CHECKBOX: - className = CheckBox.class.getName(); - setCheckable(); - break; - case AccessibilityHelper.SWITCH: - className = Switch.class.getName(); - setCheckable(); - break; - case AccessibilityHelper.CHECKED: - setChecked(); - break; - case AccessibilityHelper.DISABLED: - setDisabled(); - break; - default: - return false; - } - - return true; - } - - private boolean getCheckable() { - return (flags & CHECKABLE) != 0; - } - - private void setCheckable() { - flags |= CHECKABLE; - } - - private boolean getChecked() { - return (flags & CHECKED) != 0; - } - - private void setChecked() { - flags |= CHECKED; - } - - private boolean getDisabled() { - return (flags & DISABLED) != 0; - } - - private void setDisabled() { - flags |= DISABLED; - } - - @Override - public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) { - super.onInitializeAccessibilityEvent(host, event); - event.setClassName(className); - event.setChecked(getChecked()); - event.setEnabled(!getDisabled()); - } - - @Override - public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { - super.onInitializeAccessibilityNodeInfo(host, info); - info.setClassName(className); - info.setCheckable(getCheckable()); - info.setChecked(getChecked()); - info.setEnabled(!getDisabled()); - } -} diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java index 5afc1865e3f714..d9bcd6d4fa0bed 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java @@ -27,7 +27,6 @@ public abstract class BaseViewManager