mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-01 10:07:35 +00:00
[fix] disabled Touchable
This commit is contained in:
@@ -31,6 +31,7 @@ var merge = require('../../modules/merge');
|
|||||||
type Event = Object;
|
type Event = Object;
|
||||||
|
|
||||||
var DEFAULT_PROPS = {
|
var DEFAULT_PROPS = {
|
||||||
|
accessibilityRole: 'button',
|
||||||
activeOpacity: 0.8,
|
activeOpacity: 0.8,
|
||||||
underlayColor: 'black'
|
underlayColor: 'black'
|
||||||
};
|
};
|
||||||
@@ -234,7 +235,8 @@ var TouchableHighlight = React.createClass({
|
|||||||
<View
|
<View
|
||||||
accessible={true}
|
accessible={true}
|
||||||
accessibilityLabel={this.props.accessibilityLabel}
|
accessibilityLabel={this.props.accessibilityLabel}
|
||||||
accessibilityRole={this.props.accessibilityRole || this.props.accessibilityTraits || 'button'}
|
accessibilityRole={this.props.accessibilityRole}
|
||||||
|
disabled={this.props.disabled}
|
||||||
hitSlop={this.props.hitSlop}
|
hitSlop={this.props.hitSlop}
|
||||||
onKeyDown={(e) => { this._onKeyEnter(e, this.touchableHandleActivePressIn) }}
|
onKeyDown={(e) => { this._onKeyEnter(e, this.touchableHandleActivePressIn) }}
|
||||||
onKeyPress={(e) => { this._onKeyEnter(e, this.touchableHandlePress) }}
|
onKeyPress={(e) => { this._onKeyEnter(e, this.touchableHandlePress) }}
|
||||||
@@ -247,8 +249,12 @@ var TouchableHighlight = React.createClass({
|
|||||||
onResponderRelease={this.touchableHandleResponderRelease}
|
onResponderRelease={this.touchableHandleResponderRelease}
|
||||||
onResponderTerminate={this.touchableHandleResponderTerminate}
|
onResponderTerminate={this.touchableHandleResponderTerminate}
|
||||||
ref={UNDERLAY_REF}
|
ref={UNDERLAY_REF}
|
||||||
style={[ styles.root, this.state.underlayStyle ]}
|
style={[
|
||||||
tabIndex='0'
|
styles.root,
|
||||||
|
this.props.disabled && styles.disabled,
|
||||||
|
this.state.underlayStyle
|
||||||
|
]}
|
||||||
|
tabIndex={this.props.disabled ? null : '0'}
|
||||||
testID={this.props.testID}>
|
testID={this.props.testID}>
|
||||||
{React.cloneElement(
|
{React.cloneElement(
|
||||||
React.Children.only(this.props.children),
|
React.Children.only(this.props.children),
|
||||||
@@ -274,6 +280,9 @@ var styles = StyleSheet.create({
|
|||||||
root: {
|
root: {
|
||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
userSelect: 'none'
|
userSelect: 'none'
|
||||||
|
},
|
||||||
|
disabled: {
|
||||||
|
cursor: 'default'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ var TouchableOpacity = React.createClass({
|
|||||||
|
|
||||||
getDefaultProps: function() {
|
getDefaultProps: function() {
|
||||||
return {
|
return {
|
||||||
|
accessibilityRole: 'button',
|
||||||
activeOpacity: 0.2,
|
activeOpacity: 0.2,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -168,8 +169,14 @@ var TouchableOpacity = React.createClass({
|
|||||||
<Animated.View
|
<Animated.View
|
||||||
accessible={this.props.accessible !== false}
|
accessible={this.props.accessible !== false}
|
||||||
accessibilityLabel={this.props.accessibilityLabel}
|
accessibilityLabel={this.props.accessibilityLabel}
|
||||||
accessibilityRole={this.props.accessibilityRole || 'button'}
|
accessibilityRole={this.props.accessibilityRole}
|
||||||
style={[styles.root, this.props.style, {opacity: this.state.anim}]}
|
disabled={this.props.disabled}
|
||||||
|
style={[
|
||||||
|
styles.root,
|
||||||
|
this.props.disabled && styles.disabled,
|
||||||
|
this.props.style,
|
||||||
|
{opacity: this.state.anim}
|
||||||
|
]}
|
||||||
testID={this.props.testID}
|
testID={this.props.testID}
|
||||||
onLayout={this.props.onLayout}
|
onLayout={this.props.onLayout}
|
||||||
hitSlop={this.props.hitSlop}
|
hitSlop={this.props.hitSlop}
|
||||||
@@ -182,7 +189,7 @@ var TouchableOpacity = React.createClass({
|
|||||||
onResponderMove={this.touchableHandleResponderMove}
|
onResponderMove={this.touchableHandleResponderMove}
|
||||||
onResponderRelease={this.touchableHandleResponderRelease}
|
onResponderRelease={this.touchableHandleResponderRelease}
|
||||||
onResponderTerminate={this.touchableHandleResponderTerminate}
|
onResponderTerminate={this.touchableHandleResponderTerminate}
|
||||||
tabIndex='0'
|
tabIndex={this.props.disabled ? null : '0'}
|
||||||
>
|
>
|
||||||
{this.props.children}
|
{this.props.children}
|
||||||
</Animated.View>
|
</Animated.View>
|
||||||
@@ -194,6 +201,9 @@ var styles = StyleSheet.create({
|
|||||||
root: {
|
root: {
|
||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
userSelect: 'none'
|
userSelect: 'none'
|
||||||
|
},
|
||||||
|
disabled: {
|
||||||
|
cursor: 'default'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -161,12 +161,22 @@ const TouchableWithoutFeedback = React.createClass({
|
|||||||
children.push(Touchable.renderDebugView({color: 'red', hitSlop: this.props.hitSlop}));
|
children.push(Touchable.renderDebugView({color: 'red', hitSlop: this.props.hitSlop}));
|
||||||
}
|
}
|
||||||
const style = (Touchable.TOUCH_TARGET_DEBUG && child.type && child.type.displayName === 'Text') ?
|
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, {
|
return (React: any).cloneElement(child, {
|
||||||
accessible: this.props.accessible !== false,
|
accessible: this.props.accessible !== false,
|
||||||
accessibilityLabel: this.props.accessibilityLabel,
|
accessibilityLabel: this.props.accessibilityLabel,
|
||||||
accessibilityRole: this.props.accessibilityRole,
|
accessibilityRole: this.props.accessibilityRole,
|
||||||
|
disabled: this.props.disabled,
|
||||||
testID: this.props.testID,
|
testID: this.props.testID,
|
||||||
onLayout: this.props.onLayout,
|
onLayout: this.props.onLayout,
|
||||||
hitSlop: this.props.hitSlop,
|
hitSlop: this.props.hitSlop,
|
||||||
@@ -178,7 +188,7 @@ const TouchableWithoutFeedback = React.createClass({
|
|||||||
onResponderTerminate: this.touchableHandleResponderTerminate,
|
onResponderTerminate: this.touchableHandleResponderTerminate,
|
||||||
style,
|
style,
|
||||||
children,
|
children,
|
||||||
tabIndex: '0'
|
tabIndex: this.props.disabled ? null : '0'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -186,6 +196,9 @@ const TouchableWithoutFeedback = React.createClass({
|
|||||||
var styles = StyleSheet.create({
|
var styles = StyleSheet.create({
|
||||||
root: {
|
root: {
|
||||||
cursor: 'pointer'
|
cursor: 'pointer'
|
||||||
|
},
|
||||||
|
disabled: {
|
||||||
|
cursor: 'default'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user