Lesson 6 of 9
Gesture-Based Input Patterns
Mobile input extends beyond tap and type. Swipe to delete, long press to select, and pull to refresh are interaction patterns users expect. React Native provides these via gesture system primitives.
Swipe to Delete with Pressable
import { useRef, useState } from 'react';
import { Animated, View, Text, Pressable, StyleSheet } from 'react-native';
// Simplified swipe-to-delete (for full pan gesture, see Module 10 Reanimated)
function SwipeableItem({ title, onDelete }: { title: string; onDelete: () => void }) {
const [confirmed, setConfirmed] = useState(false);
return (
<View style={styles.itemContainer}>
{/* Main content */}
<View style={styles.item}>
<Text style={styles.itemText}>{title}</Text>
</View>
{/* Swipe actions (revealed behind) */}
<Pressable
style={styles.deleteAction}
onPress={() => {
if (confirmed) onDelete();
else setConfirmed(true); // first tap = confirm, second = delete
}}
android_ripple={{ color: '#ffffff30', borderless: false }}
accessibilityRole="button"
accessibilityLabel={`Delete ${title}`}
>
<Text style={styles.deleteText}>{confirmed ? 'Confirm' : '🗑 Delete'}</Text>
</Pressable>
</View>
);
}
// Long press to select (multi-select pattern)
function SelectableItem({ item, onToggle, isSelected }: { item: { id: string; title: string }; onToggle: () => void; isSelected: boolean }) {
return (
<Pressable
onLongPress={onToggle} // enter selection mode
onPress={() => { if (isSelected) onToggle(); }} // deselect if already selected
delayLongPress={300}
style={[styles.item, isSelected && styles.itemSelected]}
accessibilityRole="checkbox"
accessibilityState={{ checked: isSelected }}
>
{isSelected && <Text style={styles.checkmark}>✓</Text>}
<Text style={styles.itemText}>{item.title}</Text>
</Pressable>
);
}
const styles = StyleSheet.create({
itemContainer: { position: 'relative', marginBottom: 8 },
item: { backgroundColor: '#1e293b', padding: 16, borderRadius: 10, flexDirection: 'row', alignItems: 'center', gap: 12 },
itemSelected: { backgroundColor: '#164e35', borderWidth: 1.5, borderColor: '#229c6b' },
itemText: { fontSize: 15, color: '#f1f5f9', flex: 1 },
deleteAction: { position: 'absolute', right: 0, top: 0, bottom: 0, backgroundColor: '#dc2626', width: 90, borderRadius: 10, alignItems: 'center', justifyContent: 'center' },
deleteText: { color: 'white', fontWeight: '700', fontSize: 13 },
checkmark: { color: '#229c6b', fontSize: 16, fontWeight: '700' },
});Tip
Tip
Practice GestureBased Input Patterns in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
Interactive swipe-to-delete actions and tactile gesture controls in forms
Practice Task
Note
Practice Task - (1) Write a working example of GestureBased Input Patterns from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Quick Quiz
Common Mistake
Warning
A common mistake with GestureBased Input Patterns is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready react native code.
Finished this lesson?