Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Build performant React Native and Expo apps with best practices for lists, animations, and navigation
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/ui-pressable.md
1---2title: Use Pressable Instead of Touchable Components3impact: LOW4impactDescription: modern API, more flexible5tags: ui, pressable, touchable, gestures6---78## Use Pressable Instead of Touchable Components910Never use `TouchableOpacity` or `TouchableHighlight`. Use `Pressable` from11`react-native` or `react-native-gesture-handler` instead.1213**Incorrect (legacy Touchable components):**1415```tsx16import { TouchableOpacity } from 'react-native'1718function MyButton({ onPress }: { onPress: () => void }) {19return (20<TouchableOpacity onPress={onPress} activeOpacity={0.7}>21<Text>Press me</Text>22</TouchableOpacity>23)24}25```2627**Correct (Pressable):**2829```tsx30import { Pressable } from 'react-native'3132function MyButton({ onPress }: { onPress: () => void }) {33return (34<Pressable onPress={onPress}>35<Text>Press me</Text>36</Pressable>37)38}39```4041**Correct (Pressable from gesture handler for lists):**4243```tsx44import { Pressable } from 'react-native-gesture-handler'4546function ListItem({ onPress }: { onPress: () => void }) {47return (48<Pressable onPress={onPress}>49<Text>Item</Text>50</Pressable>51)52}53```5455Use `react-native-gesture-handler` Pressable inside scrollable lists for better56gesture coordination, as long as you are using the ScrollView from57`react-native-gesture-handler` as well.5859**For animated press states (scale, opacity changes):** Use `GestureDetector`60with Reanimated shared values instead of Pressable's style callback. See the61`animation-gesture-detector-press` rule.62