Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix prop overrides of TouchableWithoutFeedback #23966

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 26 additions & 10 deletions Libraries/Components/Touchable/TouchableWithoutFeedback.js
Expand Up @@ -46,6 +46,22 @@ type FocusEvent = TargetEvent;

const PRESS_RETENTION_OFFSET = {top: 20, left: 20, right: 20, bottom: 30};

const OVERRIDE_PROPS = [
'accessibilityComponentType',
'accessibilityLabel',
'accessibilityHint',
'accessibilityIgnoresInvertColors',
'accessibilityRole',
'accessibilityStates',
'accessibilityTraits',
'hitSlop',
'nativeID',
'onBlur',
'onFocus',
'onLayout',
'testID',
];

export type Props = $ReadOnly<{|
accessible?: ?boolean,
accessibilityComponentType?: ?AccessibilityComponentType,
Expand Down Expand Up @@ -92,6 +108,7 @@ const TouchableWithoutFeedback = ((createReactClass({
accessibilityComponentType: PropTypes.oneOf(
DeprecatedAccessibilityComponentTypes,
),
accessibilityIgnoresInvertColors: PropTypes.bool,
accessibilityRole: PropTypes.oneOf(DeprecatedAccessibilityRoles),
accessibilityStates: PropTypes.arrayOf(
PropTypes.oneOf(DeprecatedAccessibilityStates),
Expand Down Expand Up @@ -239,18 +256,17 @@ const TouchableWithoutFeedback = ((createReactClass({
Touchable.renderDebugView({color: 'red', hitSlop: this.props.hitSlop}),
);
}

const overrides = {};
for (const prop of OVERRIDE_PROPS) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot get this.props[prop] because property accessibilityIgnoresInvertColors is missing in propTypes of React component [1].

if (this.props[prop] !== undefined) {
overrides[prop] = this.props[prop];
}
}

return (React: any).cloneElement(child, {
...overrides,
accessible: this.props.accessible !== false,
accessibilityLabel: this.props.accessibilityLabel,
accessibilityHint: this.props.accessibilityHint,
accessibilityComponentType: this.props.accessibilityComponentType,
accessibilityRole: this.props.accessibilityRole,
accessibilityStates: this.props.accessibilityStates,
accessibilityTraits: this.props.accessibilityTraits,
nativeID: this.props.nativeID,
testID: this.props.testID,
onLayout: this.props.onLayout,
hitSlop: this.props.hitSlop,
onStartShouldSetResponder: this.touchableHandleStartShouldSetResponder,
onResponderTerminationRequest: this
.touchableHandleResponderTerminationRequest,
Expand Down