Skip to content

Commit 7190fdd

Browse files
committed
support disabled state in Incubator.TouchableOpacity
1 parent 72bb4d9 commit 7190fdd

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/incubator/TouchableOpacity.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ class TouchableOpacity extends PureComponent {
6363
/**
6464
* Pass controlled pressState to track gesture state changes
6565
*/
66-
pressState: PropTypes.object
66+
pressState: PropTypes.object,
67+
/**
68+
* If true, disable all interactions for this component.
69+
*/
70+
disabled: PropTypes.bool
6771
};
6872

6973
static defaultProps = {
@@ -124,11 +128,16 @@ class TouchableOpacity extends PureComponent {
124128
};
125129

126130
render() {
127-
const {modifiers, style, onPress, onLongPress, forwardedRef, ...others} = this.props;
131+
const {modifiers, style, onPress, onLongPress, disabled, forwardedRef, ...others} = this.props;
128132
const {borderRadius, paddings, margins, alignments, flexStyle, backgroundColor} = modifiers;
129133

130134
return (
131-
<TapGestureHandler onHandlerStateChange={this.onStateChange} shouldCancelWhenOutside ref={forwardedRef}>
135+
<TapGestureHandler
136+
onHandlerStateChange={this.onStateChange}
137+
shouldCancelWhenOutside
138+
ref={forwardedRef}
139+
enabled={!disabled}
140+
>
132141
<Reanimated.View
133142
{...others}
134143
style={[
@@ -154,9 +163,11 @@ class TouchableOpacity extends PureComponent {
154163
]);
155164
}}
156165
</Code>
157-
{onLongPress && <LongPressGestureHandler onHandlerStateChange={this.onLongPress}>
158-
<Reanimated.View style={StyleSheet.absoluteFillObject}/>
159-
</LongPressGestureHandler>}
166+
{onLongPress && (
167+
<LongPressGestureHandler onHandlerStateChange={this.onLongPress} enabled={!disabled}>
168+
<Reanimated.View style={StyleSheet.absoluteFillObject}/>
169+
</LongPressGestureHandler>
170+
)}
160171
</Reanimated.View>
161172
</TapGestureHandler>
162173
);

0 commit comments

Comments
 (0)