Skip to content

Commit

Permalink
Add userSelect to TouchableOpacity (#2812)
Browse files Browse the repository at this point in the history
## Description

As pointed in [this discussion](#2799), it is not possible to set `userSelect` property on `TouchableOpacity` component. This fixes this problem. 

## Test plan

<details>
<summary> Test code </summary>

```jsx
import React from 'react';
import { StyleSheet, View, Text } from 'react-native';
import { TouchableOpacity } from 'react-native-gesture-handler';

export default function EmptyExample() {
  return (
    <View style={styles.container}>
      <TouchableOpacity
        userSelect="auto"
        style={{ width: 100, height: 100, backgroundColor: 'darkgreen' }}>
        <Text>Test</Text>
      </TouchableOpacity>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
});
```

</details>
  • Loading branch information
m-bert authored Mar 18, 2024
1 parent 3904238 commit 6d234d0
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/components/touchables/GenericTouchable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { BaseButton } from '../GestureButtons';
import {
GestureEvent,
HandlerStateChangeEvent,
UserSelect,
} from '../../handlers/gestureHandlerCommon';
import { NativeViewGestureHandlerPayload } from '../../handlers/NativeViewGestureHandler';
import { TouchableNativeFeedbackExtraProps } from './TouchableNativeFeedback.android';
Expand Down Expand Up @@ -51,6 +52,7 @@ export interface GenericTouchableProps

containerStyle?: StyleProp<ViewStyle>;
hitSlop?: Insets | number;
userSelect?: UserSelect;
}

interface InternalProps {
Expand Down Expand Up @@ -286,6 +288,7 @@ export default class GenericTouchable extends Component<
}
onGestureEvent={this.onGestureEvent}
hitSlop={hitSlop}
userSelect={this.props.userSelect}
shouldActivateOnStart={this.props.shouldActivateOnStart}
disallowInterruption={this.props.disallowInterruption}
testID={this.props.testID}
Expand Down

0 comments on commit 6d234d0

Please sign in to comment.