Skip to content

Commit 68825f9

Browse files
aleclarsonfacebook-github-bot
authored andcommitted
Fix prop overrides of TouchableWithoutFeedback (#23966)
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
1 parent 8266f61 commit 68825f9

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

Libraries/Components/Touchable/TouchableWithoutFeedback.js

+26-10
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ type FocusEvent = TargetEvent;
4646

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

49+
const OVERRIDE_PROPS = [
50+
'accessibilityComponentType',
51+
'accessibilityLabel',
52+
'accessibilityHint',
53+
'accessibilityIgnoresInvertColors',
54+
'accessibilityRole',
55+
'accessibilityStates',
56+
'accessibilityTraits',
57+
'hitSlop',
58+
'nativeID',
59+
'onBlur',
60+
'onFocus',
61+
'onLayout',
62+
'testID',
63+
];
64+
4965
export type Props = $ReadOnly<{|
5066
accessible?: ?boolean,
5167
accessibilityComponentType?: ?AccessibilityComponentType,
@@ -92,6 +108,7 @@ const TouchableWithoutFeedback = ((createReactClass({
92108
accessibilityComponentType: PropTypes.oneOf(
93109
DeprecatedAccessibilityComponentTypes,
94110
),
111+
accessibilityIgnoresInvertColors: PropTypes.bool,
95112
accessibilityRole: PropTypes.oneOf(DeprecatedAccessibilityRoles),
96113
accessibilityStates: PropTypes.arrayOf(
97114
PropTypes.oneOf(DeprecatedAccessibilityStates),
@@ -239,18 +256,17 @@ const TouchableWithoutFeedback = ((createReactClass({
239256
Touchable.renderDebugView({color: 'red', hitSlop: this.props.hitSlop}),
240257
);
241258
}
259+
260+
const overrides = {};
261+
for (const prop of OVERRIDE_PROPS) {
262+
if (this.props[prop] !== undefined) {
263+
overrides[prop] = this.props[prop];
264+
}
265+
}
266+
242267
return (React: any).cloneElement(child, {
268+
...overrides,
243269
accessible: this.props.accessible !== false,
244-
accessibilityLabel: this.props.accessibilityLabel,
245-
accessibilityHint: this.props.accessibilityHint,
246-
accessibilityComponentType: this.props.accessibilityComponentType,
247-
accessibilityRole: this.props.accessibilityRole,
248-
accessibilityStates: this.props.accessibilityStates,
249-
accessibilityTraits: this.props.accessibilityTraits,
250-
nativeID: this.props.nativeID,
251-
testID: this.props.testID,
252-
onLayout: this.props.onLayout,
253-
hitSlop: this.props.hitSlop,
254270
onStartShouldSetResponder: this.touchableHandleStartShouldSetResponder,
255271
onResponderTerminationRequest: this
256272
.touchableHandleResponderTerminationRequest,

0 commit comments

Comments
 (0)