Swipeable list items let users quickly act on list entries by swiping left or right. This makes apps feel smooth and easy to use.
Swipeable list items in React Native
import { Swipeable } from 'react-native-gesture-handler'; function SwipeableItem({ children, renderRightActions }) { return ( <Swipeable renderRightActions={renderRightActions}> {children} </Swipeable> ); }
The Swipeable component wraps the item you want to swipe.
The renderRightActions prop is a function that returns the buttons shown when swiping left.
renderRightActions, swiping won't show buttons.import { Swipeable } from 'react-native-gesture-handler'; // Empty right actions (no buttons) function SwipeableItemEmpty({ children }) { return <Swipeable>{children}</Swipeable>; }
import { Swipeable, RectButton } from 'react-native-gesture-handler'; import { Text, View } from 'react-native'; function RightActions() { return ( <RectButton style={{backgroundColor: 'red', justifyContent: 'center', flex: 1}}> <Text style={{color: 'white', paddingHorizontal: 20}}>Delete</Text> </RectButton> ); } function SwipeableItemWithDelete({ children }) { return <Swipeable renderRightActions={RightActions}>{children}</Swipeable>; }
import { Swipeable, RectButton } from 'react-native-gesture-handler'; import { Text, View } from 'react-native'; function MultipleRightActions() { return ( <View style={{flexDirection: 'row', width: 160}}> <RectButton style={{backgroundColor: 'blue', justifyContent: 'center', flex: 1}}> <Text style={{color: 'white', paddingHorizontal: 10}}>Edit</Text> </RectButton> <RectButton style={{backgroundColor: 'red', justifyContent: 'center', flex: 1}}> <Text style={{color: 'white', paddingHorizontal: 10}}>Delete</Text> </RectButton> </View> ); } function SwipeableItemMultiple({ children }) { return <Swipeable renderRightActions={MultipleRightActions}>{children}</Swipeable>; }
This app shows a list of items. Swipe left on any item to reveal a red Delete button. Pressing Delete shows an alert with the item name.
import React from 'react'; import { View, Text, FlatList, StyleSheet, Alert } from 'react-native'; import { Swipeable, RectButton, GestureHandlerRootView } from 'react-native-gesture-handler'; const DATA = [ { id: '1', title: 'First Item' }, { id: '2', title: 'Second Item' }, { id: '3', title: 'Third Item' } ]; function RightActions({ onDelete }) { return ( <RectButton style={styles.rightAction} onPress={onDelete}> <Text style={styles.actionText}>Delete</Text> </RectButton> ); } export default function App() { const renderItem = ({ item }) => { const handleDelete = () => { Alert.alert('Delete', `Delete ${item.title}?`); }; return ( <Swipeable renderRightActions={() => <RightActions onDelete={handleDelete} />}> <View style={styles.item}> <Text style={styles.title}>{item.title}</Text> </View> </Swipeable> ); }; return ( <GestureHandlerRootView style={{ flex: 1 }}> <FlatList data={DATA} keyExtractor={item => item.id} renderItem={renderItem} /> </GestureHandlerRootView> ); } const styles = StyleSheet.create({ item: { backgroundColor: 'white', padding: 20, borderBottomColor: '#ccc', borderBottomWidth: 1 }, title: { fontSize: 18 }, rightAction: { backgroundColor: 'red', justifyContent: 'center', alignItems: 'flex-end', paddingHorizontal: 20, flex: 1 }, actionText: { color: 'white', fontWeight: '600' } });
Swipeable actions run in O(1) time since they just show/hide UI elements.
Keep swipe areas large enough for easy tapping on mobile.
Common mistake: forgetting to wrap the app in GestureHandlerRootView causes gestures not to work.
Use swipe actions for quick tasks like delete or archive, but avoid overloading with too many buttons.
Swipeable list items improve user experience by adding quick gesture actions.
Use Swipeable from react-native-gesture-handler to create swipeable rows.
Provide renderRightActions or renderLeftActions to show buttons when swiping.
Practice
Swipeable in React Native list items?Solution
Step 1: Understand Swipeable component role
TheSwipeablecomponent enables swipe gestures on list items.Step 2: Identify the effect of swiping
Swiping reveals hidden buttons or actions like delete or edit.Final Answer:
To allow users to swipe list items and reveal hidden actions -> Option AQuick Check:
Swipeable = Reveal actions on swipe [OK]
- Thinking Swipeable sorts items automatically
- Confusing swipe with tap animations
- Assuming Swipeable disables scrolling
Swipeable?Solution
Step 1: Recall Swipeable props for swipe actions
renderLeftActionsdefines buttons shown when swiping to the right (revealing left side).Step 2: Match prop to swipe direction
Swiping to the right reveals buttons from the left side, sorenderLeftActionsis correct.Final Answer:
renderLeftActions -> Option AQuick Check:
Right swipe buttons = renderLeftActions [OK]
- Confusing renderRightActions with right swipe
- Using non-existent prop onSwipeRight
- Assuming swipeButtons is a valid prop
import { Swipeable } from 'react-native-gesture-handler';
function ListItem() {
return (
}
>
Message
);
}Solution
Step 1: Understand renderLeftActions behavior
renderLeftActionsshows buttons when swiping to the right (revealing left side).Step 2: Analyze swipe to the left
Swiping to the left reveals right side actions viarenderRightActions, which is not provided, so no button appears.Final Answer:
No button appears on swipe -> Option BQuick Check:
Swipe left requires renderRightActions [OK]
- Thinking renderLeftActions shows on swipe left
- Confusing the swipe direction for left actions
- Expecting immediate deletion on swipe
import { Swipeable } from 'react-native-gesture-handler';
function Item() {
return (
Delete}
>
Item
);
}Solution
Step 1: Check renderRightActions return type
Swipe actions should be interactive buttons or touchable components, not plainText.Step 2: Identify correct component usage
UsingTextalone won't respond to touches; useTouchableOpacityorButton.Final Answer:
Text component cannot be used directly as a swipe action button -> Option DQuick Check:
Swipe actions need touchable components [OK]
- Using plain Text instead of touchable components
- Thinking renderRightActions is a boolean
- Assuming Swipeable can't wrap Text
Solution
Step 1: Match swipe directions to actions
Swiping left means moving finger leftwards, revealing right side actions, so 'Delete' should be on right.Step 2: Assign correct props
renderRightActionsshows buttons on right side (swipe left),renderLeftActionsshows buttons on left side (swipe right).Step 3: Check button components
Buttons are used correctly, not plain Text.Final Answer:
renderLeftActions shows 'Archive', renderRightActions shows 'Delete' -> Option CQuick Check:
Left swipe = right actions, right swipe = left actions [OK]
- Swapping left and right actions
- Using plain Text instead of buttons
- Using wrong prop names like leftActions
Ready to prove it?
Pass the test and this pattern moves unknown
