Skip to content

Commit

Permalink
Fix prop overrides of TouchableWithoutFeedback (#23966)
Browse files Browse the repository at this point in the history
Summary:
Child props were being overridden by `<Touchable>` props even when the `<Touchable>` props were undefined.

[General] [Fixed] - Prevent prop override by TouchableWithoutFeedback when undefined
Pull Request resolved: #23966

Differential Revision: D14502918

Pulled By: cpojer

fbshipit-source-id: 614ee43bbb6f062a98bd9318693807320979a016
  • Loading branch information
aleclarson authored and facebook-github-bot committed Mar 18, 2019
1 parent 8266f61 commit 68825f9
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions Libraries/Components/Touchable/TouchableWithoutFeedback.js
Original file line number Diff line number Diff line change
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) {
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

0 comments on commit 68825f9

Please sign in to comment.