From be923ec4530f55ba59b6e603548801059e998491 Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Tue, 16 Aug 2016 10:29:26 -0700 Subject: [PATCH] [fix] disabled Touchable --- .../Touchable/TouchableHighlight.js | 15 ++++++++++++--- src/components/Touchable/TouchableOpacity.js | 16 +++++++++++++--- .../Touchable/TouchableWithoutFeedback.js | 19 ++++++++++++++++--- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/components/Touchable/TouchableHighlight.js b/src/components/Touchable/TouchableHighlight.js index 5da588d6..49605cfe 100644 --- a/src/components/Touchable/TouchableHighlight.js +++ b/src/components/Touchable/TouchableHighlight.js @@ -31,6 +31,7 @@ var merge = require('../../modules/merge'); type Event = Object; var DEFAULT_PROPS = { + accessibilityRole: 'button', activeOpacity: 0.8, underlayColor: 'black' }; @@ -234,7 +235,8 @@ var TouchableHighlight = React.createClass({ { this._onKeyEnter(e, this.touchableHandleActivePressIn) }} onKeyPress={(e) => { this._onKeyEnter(e, this.touchableHandlePress) }} @@ -247,8 +249,12 @@ var TouchableHighlight = React.createClass({ onResponderRelease={this.touchableHandleResponderRelease} onResponderTerminate={this.touchableHandleResponderTerminate} ref={UNDERLAY_REF} - style={[ styles.root, this.state.underlayStyle ]} - tabIndex='0' + style={[ + styles.root, + this.props.disabled && styles.disabled, + this.state.underlayStyle + ]} + tabIndex={this.props.disabled ? null : '0'} testID={this.props.testID}> {React.cloneElement( React.Children.only(this.props.children), @@ -274,6 +280,9 @@ var styles = StyleSheet.create({ root: { cursor: 'pointer', userSelect: 'none' + }, + disabled: { + cursor: 'default' } }); diff --git a/src/components/Touchable/TouchableOpacity.js b/src/components/Touchable/TouchableOpacity.js index f4d1a9ba..bb72b841 100644 --- a/src/components/Touchable/TouchableOpacity.js +++ b/src/components/Touchable/TouchableOpacity.js @@ -64,6 +64,7 @@ var TouchableOpacity = React.createClass({ getDefaultProps: function() { return { + accessibilityRole: 'button', activeOpacity: 0.2, }; }, @@ -168,8 +169,14 @@ var TouchableOpacity = React.createClass({ {this.props.children} @@ -194,6 +201,9 @@ var styles = StyleSheet.create({ root: { cursor: 'pointer', userSelect: 'none' + }, + disabled: { + cursor: 'default' } }); diff --git a/src/components/Touchable/TouchableWithoutFeedback.js b/src/components/Touchable/TouchableWithoutFeedback.js index aca47c68..e44ade1a 100644 --- a/src/components/Touchable/TouchableWithoutFeedback.js +++ b/src/components/Touchable/TouchableWithoutFeedback.js @@ -161,12 +161,22 @@ const TouchableWithoutFeedback = React.createClass({ children.push(Touchable.renderDebugView({color: 'red', hitSlop: this.props.hitSlop})); } const style = (Touchable.TOUCH_TARGET_DEBUG && child.type && child.type.displayName === 'Text') ? - [styles.root, child.props.style, {color: 'red'}] : - [styles.root, child.props.style]; + [ + styles.root, + this.props.disabled && styles.disabled, + child.props.style, + {color: 'red'} + ] : + [ + styles.root, + this.props.disabled && styles.disabled, + child.props.style + ]; return (React: any).cloneElement(child, { accessible: this.props.accessible !== false, accessibilityLabel: this.props.accessibilityLabel, accessibilityRole: this.props.accessibilityRole, + disabled: this.props.disabled, testID: this.props.testID, onLayout: this.props.onLayout, hitSlop: this.props.hitSlop, @@ -178,7 +188,7 @@ const TouchableWithoutFeedback = React.createClass({ onResponderTerminate: this.touchableHandleResponderTerminate, style, children, - tabIndex: '0' + tabIndex: this.props.disabled ? null : '0' }); } }); @@ -186,6 +196,9 @@ const TouchableWithoutFeedback = React.createClass({ var styles = StyleSheet.create({ root: { cursor: 'pointer' + }, + disabled: { + cursor: 'default' } });