53
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, Image, Animated } from 'react-native';
import {PanGestureHandler} from 'react-native-gesture-handler';
const profiles = [
{
name:"John Doe",
age:27,
likes:["Hockey","Hiking"],
pic:"https://i.picsum.photos/id/875/400/700.jpg?hmac=lRCTTEqKWD92eBmpH4wlQzMAlimbfZlquoOe63Mnk0g"
},
{
name:"Alexis Texas",
age:22,
likes:["Parties","Bananas"],
pic:"https://i.picsum.photos/id/657/400/700.jpg?hmac=4lzNCpLyxL1P5xiJN4wFe9sqVK0DgL5OSuHIcESjIVs"
},
{
name:"Jane Smith",
age:35,
likes:["Netflix","Wine"],
pic:"https://i.picsum.photos/id/47/400/700.jpg?hmac=TQCJf6PQAtKGOEKHlgf3xN-JusmYrre3czFnX3AWf5M"
}
]
let index = 0
export default function App() {
const [profile,setProfile] = useState(profiles[0])
return (
<SafeAreaView style={styles.container}>
<View style={styles.cardContainer}>
<PanGestureHandler>
<Animated.View style={[styles.card]}>
<Image source={{uri: profile.pic}} style={{height:"80%",width:"100%"}}></Image>
<View style={{flex:1,alignContent:'center',justifyContent:'center'}}>
<Text style={{fontSize:20,fontWeight:"700"}}>{profile.name}</Text>
<Text>Age: {profile.age}</Text>
<Text>Likes: {profile.likes.join(', ')}</Text>
</View>
</Animated.View>
</PanGestureHandler>
</View>
<StatusBar style="auto" />
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
margin:10,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
cardContainer:{
flex:1,
width:"100%",
alignItems: 'center',
justifyContent: 'center'
},
card:{
backgroundColor: "rgb(230,230,230)",
width:"100%",
height:"100%",
borderRadius: 5,
position:'absolute',
borderWidth:1.5,
borderColor:'black',
alignItems: 'center',
justifyContent: 'center'
}
});
export default function App() {
const [profile,setProfile] = useState(profiles[0])
const translateX = new Animated.Value(0)
const translateY = new Animated.Value(0)
<Animated.View style={[styles.card],{transform:[{translateX},{translateY}]>
<Image source={{uri: profile.pic}} style={{height:"80%",width:"100%"}}></Image>
<View style={{flex:1,alignContent:'center',justifyContent:'center'}}>
<Text style={{fontSize:20,fontWeight:"700"}}>{profile.name}</Text>
<Text>Age: {profile.age}</Text>
<Text>Likes: {profile.likes.join(', ')}</Text>
</View>
</Animated.View>
const handlePan = Animated.event(
[{nativeEvent:{translationX:translateX,translationY:translateY}}],{useNativeDriver:true}
)
<PanGestureHandler onGestureEvent={handlePan}>
const y = new Animated.Value(0)
const handlePan = Animated.event(
[{nativeEvent:{translationX:translateX,translationY:translateY,y}}],{useNativeDriver:true}
)
Import {Dimensions} from 'react-native';
const y = new Animated.Value(0)
const windowHeight = Dimensions.get('window').height
const TopOrBottom = y.interpolate({inputRange:[0,windowHeight/2-1,windowHeight/2],outputRange:[1,1,-1],extrapolate:'clamp'})
const rotate = Animated.multiply(translateX,TopOrBottom).interpolate({
inputRange:[-500,500],
outputRange:[`-30deg`,`30deg`],
extrapolate:'clamp'
})
<Animated.View style={[styles.card, {transform:[{translateX},{translateY},{rotate}]}]}>