
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
react-native-swipeable-item
Advanced tools
A swipeable component with underlay for React Native.
Fully native interactions powered by Reanimated and React Native Gesture Handler
Compatible with React Native Draggable Flatlist
npm install
or yarn add
react-native-swipeable-item
import SwipeItem from 'react-native-swipeable-Item'
Name | Type | Description |
---|---|---|
renderUnderlay | () => React.ReactNode | Component to be rendered underneath row. |
underlayWidth | number | Width of underlay. |
swipeThreshold | number | Swipe threshold for underlay to remain open on release. |
onOpen | () => void | Called when row is opened. |
onClose | () => void | Called when row is closed. |
import * as React from 'react';
const { useCallback, useState } = React;
import {
Text,
View,
StyleSheet,
FlatList,
LayoutAnimation,
TouchableOpacity,
} from 'react-native';
import SwipeRow from './components/SwipeRow';
const NUM_ITEMS = 10;
function getColor(i) {
const multiplier = 255 / (NUM_ITEMS - 1);
const colorVal = i * multiplier;
return `rgb(${colorVal}, ${Math.abs(128 - colorVal)}, ${255 - colorVal})`;
}
const initialData = [...Array(NUM_ITEMS)].fill(0).map((d, index) => ({
text: `Row ${index}`,
key: `key-${index}`, // Note: It's bad practice to use index as your key. Don't do it in production!
backgroundColor: getColor(index),
}));
class App extends React.Component {
state = {
data: initialData,
};
refMap = new Map();
openMap = new Map();
deleteItem = item => {
const updatedData = this.state.data.filter(d => d !== item);
// Animate list to close gap when item is deleted
LayoutAnimation.configureNext(LayoutAnimation.Presets.spring);
this.setState({ data: updatedData });
};
renderItem = ({ item, index }) => (
<SwipeRow
ref={ref => this.refMap.set(item.key, ref)}
key={item.key}
underlayWidth={200}
swipeThreshold={-150}
onOpen={() => this.openMap.set(item.key, true)}
onClose={() => this.openMap.set(item.key, false)}
renderUnderlay={() => {
return (
<View style={styles.underlay}>
<TouchableOpacity onPress={() => this.deleteItem(item)}>
<Text style={styles.text}>DEL</Text>
</TouchableOpacity>
</View>
);
}}>
<View
style={{ flexDirection: 'row', backgroundColor: item.backgroundColor }}>
<Text style={styles.text}>{item.text}</Text>
<TouchableOpacity
onPress={() => {
const ref = this.refMap.get(item.key);
if (ref) {
if (this.openMap.get(item.key)) ref.close();
else ref.open();
}
}}>
<Text style={styles.text}>{`<>`}</Text>
</TouchableOpacity>
</View>
</SwipeRow>
);
render() {
return (
<View style={styles.container}>
<FlatList data={this.state.data} renderItem={this.renderItem} />
</View>
);
}
}
export default App;
const styles = StyleSheet.create({
container: {
flex: 1,
},
text: {
fontWeight: 'bold',
color: 'white',
fontSize: 32,
flex: 1,
textAlign: 'center',
padding: 25,
},
underlay: {
flex: 1,
backgroundColor: 'tomato',
alignItems: 'flex-end'
}
});
FAQs
A horizontally swipeable flatlist row compatible with react-native-draggable-flatlist
The npm package react-native-swipeable-item receives a total of 3,602 weekly downloads. As such, react-native-swipeable-item popularity was classified as popular.
We found that react-native-swipeable-item demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.