From 5e1e0ec8e580a2ea9814a8b8c628083021460c70 Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Sun, 10 Jul 2016 22:15:24 -0700 Subject: [PATCH] [fix] update Touchables --- src/components/Touchable/Touchable.js | 2 +- .../Touchable/TouchableHighlight.js | 2 +- src/components/Touchable/TouchableOpacity.js | 2 +- .../Touchable/TouchableWithoutFeedback.js | 29 +++++++++++++++---- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/components/Touchable/Touchable.js b/src/components/Touchable/Touchable.js index ab779f48..7e2027dd 100644 --- a/src/components/Touchable/Touchable.js +++ b/src/components/Touchable/Touchable.js @@ -735,7 +735,7 @@ var Touchable = { if (!Touchable.TOUCH_TARGET_DEBUG) { return null; } - if (!__DEV__) { + if (process.env.NODE_ENV === 'production') { throw Error('Touchable.TOUCH_TARGET_DEBUG should not be enabled in prod!'); } const debugHitSlopStyle = {}; diff --git a/src/components/Touchable/TouchableHighlight.js b/src/components/Touchable/TouchableHighlight.js index c1c44a0f..c2f35260 100644 --- a/src/components/Touchable/TouchableHighlight.js +++ b/src/components/Touchable/TouchableHighlight.js @@ -247,7 +247,7 @@ var TouchableHighlight = React.createClass({ onResponderRelease={this.touchableHandleResponderRelease} onResponderTerminate={this.touchableHandleResponderTerminate} ref={UNDERLAY_REF} - style={[styles.root, this.props.style]} + style={this.state.underlayStyle} tabIndex='0' testID={this.props.testID}> {React.cloneElement( diff --git a/src/components/Touchable/TouchableOpacity.js b/src/components/Touchable/TouchableOpacity.js index 30c787ba..f4d1a9ba 100644 --- a/src/components/Touchable/TouchableOpacity.js +++ b/src/components/Touchable/TouchableOpacity.js @@ -166,7 +166,7 @@ var TouchableOpacity = React.createClass({ render: function() { return ( * > If you wish to have several child components, wrap them in a View. */ -var TouchableWithoutFeedback = React.createClass({ +const TouchableWithoutFeedback = React.createClass({ mixins: [TimerMixin, Touchable.Mixin], propTypes: { - accessible: React.PropTypes.bool, - accessibilityLabel: View.propTypes.accessibilityLabel, + accessible: View.propTypes.accessible, + aaccessibilityLabel: View.propTypes.accessibilityLabel, accessibilityRole: View.propTypes.accessibilityRole, /** * If true, disable all interactions for this component. @@ -143,9 +144,25 @@ var TouchableWithoutFeedback = React.createClass({ return this.props.delayPressOut || 0; }, - render: function(): ReactElement { + render: function(): ReactElement { // Note(avik): remove dynamic typecast once Flow has been upgraded - return (React: any).cloneElement(React.Children.only(this.props.children), { + const child = React.Children.only(this.props.children); + let children = child.props.children; + warning( + !child.type || child.type.displayName !== 'Text', + 'TouchableWithoutFeedback does not work well with Text children. Wrap children in a View instead. See ' + + ((child._owner && child._owner.getName && child._owner.getName()) || '') + ); + if (Touchable.TOUCH_TARGET_DEBUG && child.type && child.type.displayName === 'View') { + if (!Array.isArray(children)) { + children = [children]; + } + children.push(Touchable.renderDebugView({color: 'red', hitSlop: this.props.hitSlop})); + } + const style = (Touchable.TOUCH_TARGET_DEBUG && child.type && child.type.displayName === 'Text') ? + [child.props.style, {color: 'red'}] : + child.props.style; + return (React: any).cloneElement(child, { accessible: this.props.accessible !== false, accessibilityLabel: this.props.accessibilityLabel, accessibilityRole: this.props.accessibilityRole, @@ -158,6 +175,8 @@ var TouchableWithoutFeedback = React.createClass({ onResponderMove: this.touchableHandleResponderMove, onResponderRelease: this.touchableHandleResponderRelease, onResponderTerminate: this.touchableHandleResponderTerminate, + style, + children, tabIndex: '0' }); }