122
loading...
This website collects cookies to deliver better user experience
import { StatusBar } from 'expo-status-bar';
import { SafeAreaView } from 'react-native-safe-area-context';
import React, {useState} from 'react';
import { StyleSheet, Text, View, Animated, FlatList } from 'react-native';
import Swipeable from 'react-native-gesture-handler/Swipeable';
import data from './Exampledata'
function ListItem({email}){
const {title, sender, subject} = email
return(
<Animated.View style={{flex:1,flexDirection:'row', height:70, alignItems:'center',borderBottomWidth:1,backgroundColor:'white'}}>
<Text style={{width:150}}>{title}</Text>
<View style={{overflow:'visible'}}>
<Text>From: {sender}</Text>
<Text>Subject: {subject}</Text>
</View>
</Animated.View>
)
}
export default function App() {
const [emails, setEmails] = useState(data)
return (
<SafeAreaView style={styles.container}>
<FlatList
data={emails}
renderItem={({item}) =><ListItem email={item}/>}
/>
<StatusBar style="auto" />
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
marginTop:20,
marginHorizontal:10,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
function ListItem({email}){
const {title, sender, subject} = email
const swipeRight = (progress,dragX) =>{
const scale = dragX.interpolate({
inputRange:[-200,0],
outputRange:[1,0.5],
extrapolate:'clamp'
})
return(
<Animated.View style={{backgroundColor:'red',width:"100%",justifyContent:'center'}}>
<Animated.Text style={{marginLeft:'auto',marginRight:50, fontSize:15, fontWeight:'bold',transform:[{scale}]}}>Delete Item</Animated.Text>
</Animated.View>
)
}
return(
<Swipeable renderRightActions={swipeRight} rightThreshold={-200}>
<Animated.View style={{flex:1,flexDirection:'row', height:70, alignItems:'center',borderBottomWidth:1,backgroundColor:'white'}}>
<Text style={{width:150}}>{title}</Text>
<View style={{overflow:'visible'}}>
<Text>From: {sender}</Text>
<Text>Subject: {subject}</Text>
</View>
</Animated.View>
</Swipeable>
)
}
const height = new Animated.Value(70)
const animatedDelete=() => {
Animated.timing(height,{
toValue: 0,
duration: 350,
useNativeDriver:false
}).start()
}
<Swipeable renderRightActions={swipeRight} rightThreshold={-200} onSwipeableOpen={animatedDelete}>
const animatedDelete=() => {
Animated.timing(height,{
toValue: 0,
duration: 350,
useNativeDriver:false
}).start(() => setEmails(prevState => prevState.filter(e => e.id !== email.id)))
}