From 68825f9ca5a6c8c70390e8499d9663c5be475639 Mon Sep 17 00:00:00 2001 From: Alec Larson Date: Mon, 18 Mar 2019 10:46:30 -0700 Subject: [PATCH] Fix prop overrides of TouchableWithoutFeedback (#23966) Summary: Child props were being overridden by `` props even when the `` props were undefined. [General] [Fixed] - Prevent prop override by TouchableWithoutFeedback when undefined Pull Request resolved: https://github.com/facebook/react-native/pull/23966 Differential Revision: D14502918 Pulled By: cpojer fbshipit-source-id: 614ee43bbb6f062a98bd9318693807320979a016 --- .../Touchable/TouchableWithoutFeedback.js | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/Libraries/Components/Touchable/TouchableWithoutFeedback.js b/Libraries/Components/Touchable/TouchableWithoutFeedback.js index be072554dc97b2..a78de287e41e77 100755 --- a/Libraries/Components/Touchable/TouchableWithoutFeedback.js +++ b/Libraries/Components/Touchable/TouchableWithoutFeedback.js @@ -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, @@ -92,6 +108,7 @@ const TouchableWithoutFeedback = ((createReactClass({ accessibilityComponentType: PropTypes.oneOf( DeprecatedAccessibilityComponentTypes, ), + accessibilityIgnoresInvertColors: PropTypes.bool, accessibilityRole: PropTypes.oneOf(DeprecatedAccessibilityRoles), accessibilityStates: PropTypes.arrayOf( PropTypes.oneOf(DeprecatedAccessibilityStates), @@ -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,