-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathPlaceholderBackCards.js
77 lines (68 loc) · 1.68 KB
/
PlaceholderBackCards.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
65
66
67
68
69
70
71
72
73
74
75
76
77
import {times} from 'lodash';
import Animated, {
useSharedValue,
useAnimatedStyle,
withTiming,
withDelay,
} from 'react-native-reanimated';
import {StyleSheet, View} from 'react-native';
import React, {useEffect} from 'react';
import CardReverse from './CardReverse';
const PlaceholderBackCards = () => {
const openAnimation = useSharedValue(-2);
useEffect(() => {
openAnimation.value = 0;
}, [openAnimation]);
function cardTransform(index) {
return () => {
'worklet';
const localTranslateX = withDelay(
250 - index * 50,
withTiming(openAnimation.value * 200, {duration: 800}),
);
const localTranslateY = withDelay(
250 - index * 50,
withTiming(openAnimation.value * 50, {duration: 800}),
);
return {
transform: [
{translateX: localTranslateX},
{translateY: localTranslateY},
{rotateY: '180deg'},
],
zIndex: index,
};
};
}
const Card = ({index}) => {
return (
<Animated.View
style={[useAnimatedStyle(cardTransform(index)), styles.wrapperBack]}>
<CardReverse shadowOpacity={0.2 - index * 0.05} />
</Animated.View>
);
};
return (
<View style={styles.cardWrapper}>
{times(5, (index) => {
return <Card key={`card_${index}`} index={index} />;
})}
</View>
);
};
const styles = StyleSheet.create({
wrapperBack: {
position: 'absolute',
height: 240,
width: 240,
backgroundColor: '#aaa',
borderRadius: 35,
overflow: 'hidden',
},
cardWrapper: {
height: 240,
position: 'absolute',
alignItems: 'center',
},
});
export default PlaceholderBackCards;