-
Notifications
You must be signed in to change notification settings - Fork 3
/
ImageCard.js
64 lines (61 loc) · 1.76 KB
/
ImageCard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import LottieView from 'lottie-react-native';
import React, {useRef, useState} from 'react';
import {Animated, Image, Pressable, Text, View} from 'react-native';
import styles from './AppStyles';
import Assets from './assets';
export const ImageCard = ({data}) => {
const [isLiked, setIsLiked] = useState(false);
const [processing, setProcessing] = useState(false);
const animationProgress = useRef(new Animated.Value(0)).current;
const showAnimation = () => {
setProcessing(true);
animationProgress.setValue(0);
Animated.timing(animationProgress, {
toValue: 1,
duration: 2000,
useNativeDriver: true,
}).start(({finished}) => {
if (finished) {
setIsLiked(!isLiked);
setProcessing(false);
}
});
};
return (
<Pressable
key={data?.key}
style={styles.item}
activeOpacity={1}
onLongPress={() => showAnimation()}>
{processing && (
<Animated.View
style={[
styles.overlayLottie,
{
opacity: animationProgress.interpolate({
inputRange: [0, 0.1, 0.9, 1],
outputRange: [0, 1, 1, 0],
extrapolate: 'clamp',
}),
},
]}>
<LottieView
progress={animationProgress}
source={
isLiked ? Assets.lottieFiles.unLike : Assets.lottieFiles.like
}
/>
</Animated.View>
)}
<Image
source={{uri: data?.img}}
resizeMode={'cover'}
style={styles.itemImage}
/>
<View style={styles.cardRow}>
<Text style={styles.itemText}>{data?.title}</Text>
<Text style={styles.likeText}>{isLiked ? 'UnLike' : 'Like'}</Text>
</View>
</Pressable>
);
};