Skip to main content

Swipe Row

#SwipeRow -Slide operation

Effect demonstration

1. Default effect (default with delete action item)

<SwipeRowContextProvider>
<FlatList
data={[
{ id: 1, name: "React Native" },
{ id: 2, name: "Flutter" },
]}
keyExtractor={(item) => item.id.toString()}
renderItem={({ item, index }) => (
<SwipeRow actionWidth={80} anchor={item.id}>
<View style={styles.rowContent}>
<View style={styles.rowIcon} />
<View>
<Text style={styles.rowTitle}>{item.name}</Text>
<Text style={styles.rowSubtitle}>Drag the row left and right</Text>
</View>
</View>
</SwipeRow>
)}
/>
</SwipeRowContextProvider>
...
const styles = StyleSheet.create({
rowContent: {
backgroundColor: '#FFF',
padding: 24,
borderBottomWidth: 1,
borderBottomColor: '#E3E9ED',
flexDirection: 'row',
alignItems: 'center',
},
rowIcon: {
width: 12,
height: 12,
borderRadius: 99,
backgroundColor: '#3f3efe',
marginRight: 12,
},
rowTitle: {
fontSize: 16,
fontWeight: 'bold',
},
rowSubtitle: {
fontSize: 14,
fontWeight: '400',
opacity: 0.7,
},
});

2. Right slide action item

<SwipeRowContextProvider>
<FlatList
data={[
{ id: 1, name: "React Native" },
{ id: 2, name: "Flutter" },
]}
keyExtractor={(item) => item.id.toString()}
renderItem={({ item, index }) => (
<SwipeRow
anchor={item.id}
actions={[
{
label: "warn",
onPress: () => console.log("warn"),
backgroundColor: "#4f7db0",
},
]}
actionWidth={80}
>
<View style={styles.rowContent}>
<View style={styles.rowIcon} />
<View>
<Text style={styles.rowTitle}>{item.name}</Text>
<Text style={styles.rowSubtitle}>Drag the row left and right</Text>
</View>
</View>
</SwipeRow>
)}
/>
</SwipeRowContextProvider>
...
const styles = StyleSheet.create({
rowContent: {
backgroundColor: '#FFF',
padding: 24,
borderBottomWidth: 1,
borderBottomColor: '#E3E9ED',
flexDirection: 'row',
alignItems: 'center',
},
rowIcon: {
width: 12,
height: 12,
borderRadius: 99,
backgroundColor: '#3f3efe',
marginRight: 12,
},
rowTitle: {
fontSize: 16,
fontWeight: 'bold',
},
rowSubtitle: {
fontSize: 14,
fontWeight: '400',
opacity: 0.7,
},
});

3. Override default action items

<SwipeRowContextProvider>
<FlatList
data={[
{ id: 1, name: "React Native" },
{ id: 2, name: "Flutter" },
]}
keyExtractor={(item) => item.id.toString()}
renderItem={({ item, index }) => (
<SwipeRow
anchor={item.id}
actions={[
{
label: "warning",
onPress: () => Alert.alert("Warning"),
backgroundColor: "#4f7db0",
},
]}
actionWidth={80}
overwriteDefaultActions
>
<View style={styles.rowContent}>
<View style={styles.rowIcon} />
<View>
<Text style={styles.rowTitle}>{item.name}</Text>
<Text style={styles.rowSubtitle}>Drag the row left and right</Text>
</View>
</View>
</SwipeRow>
)}
/>
</SwipeRowContextProvider>

API

SwipeRow

PropertiesRequiredDescriptionTypeDefault Value
anchortrueAs a basis for judging mutual exclusion of sliding operationsReactText
actionsfalseAction items that slide out on the right sideSwipeAction[][]
heightfalserow heightnumber60
actionWidthfalseThe width of each action itemnumberheight
onRemovefalseDelete event() => void
overwriteDefaultActionsfalseWhether to overwrite the default action itemsbooleanfalse
containerStylefalseSlider styleViewStyle
contentContainerStylefalseSlider subcomponent styleViewStyle

SwipeAction

PropertiesRequiredDescriptionTypeDefault Value
labeltrueaction textstring
textStylefalseAction item text styleTextStyle
onPresstrueAction item click event() => void
backgroundColortruebackground colorstring