-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslideanimation.tsx
108 lines (103 loc) · 3.64 KB
/
slideanimation.tsx
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Inspiration: https://dribbble.com/shots/14139308-Simple-Scroll-Animation
// Illustrations by: SAMji https://dribbble.com/SAMji_illustrator
import * as React from "react";
import {
StatusBar,
FlatList,
Image,
Animated,
Text,
View,
Dimensions,
StyleSheet,
TouchableOpacity,
} from "react-native";
const { width, height } = Dimensions.get("screen");
const data = [
"https://cdn.dribbble.com/users/3281732/screenshots/11192830/media/7690704fa8f0566d572a085637dd1eee.jpg?compress=1&resize=1200x1200",
"https://cdn.dribbble.com/users/3281732/screenshots/13130602/media/592ccac0a949b39f058a297fd1faa38e.jpg?compress=1&resize=1200x1200",
"https://cdn.dribbble.com/users/3281732/screenshots/9165292/media/ccbfbce040e1941972dbc6a378c35e98.jpg?compress=1&resize=1200x1200",
"https://cdn.dribbble.com/users/3281732/screenshots/11205211/media/44c854b0a6e381340fbefe276e03e8e4.jpg?compress=1&resize=1200x1200",
"https://cdn.dribbble.com/users/3281732/screenshots/7003560/media/48d5ac3503d204751a2890ba82cc42ad.jpg?compress=1&resize=1200x1200",
"https://cdn.dribbble.com/users/3281732/screenshots/6727912/samji_illustrator.jpeg?compress=1&resize=1200x1200",
"https://cdn.dribbble.com/users/3281732/screenshots/13661330/media/1d9d3cd01504fa3f5ae5016e5ec3a313.jpg?compress=1&resize=1200x1200",
"https://cdn.dribbble.com/users/3281732/screenshots/11192830/media/7690704fa8f0566d572a085637dd1eee.jpg?compress=1&resize=1200x1200",
"https://cdn.dribbble.com/users/3281732/screenshots/13130602/media/592ccac0a949b39f058a297fd1faa38e.jpg?compress=1&resize=1200x1200",
"https://cdn.dribbble.com/users/3281732/screenshots/9165292/media/ccbfbce040e1941972dbc6a378c35e98.jpg?compress=1&resize=1200x1200",
];
const imageW = width * 0.7;
const imageH = imageW * 1.54;
export default () => {
const scrollx = React.useRef(new Animated.Value(0)).current;
return (
<View style={{ flex: 1, backgroundColor: "#000" }}>
<View
style={[StyleSheet.absoluteFillObject, { justifyContent: "center" }]}
>
{data?.map((image, index) => {
const inputRange = [
(index - 1) * width,
index * width,
(index + 1) * width,
];
const opacity = scrollx.interpolate({
inputRange,
outputRange: [0, 1, 0],
});
return (
<Animated.Image
key={`image - ${index}`}
source={{ uri: image }}
style={[
StyleSheet.absoluteFillObject,
{
opacity,
},
]}
blurRadius={50}
/>
);
})}
</View>
<StatusBar />
<Animated.FlatList
onScroll={Animated.event(
[{ nativeEvent: { contentOffset: { x: scrollx } } }],
{ useNativeDriver: true }
)}
data={data}
keyExtractor={(_, index) => index.toString()}
horizontal
pagingEnabled
renderItem={({ item }) => {
return (
<View
style={{
width,
justifyContent: "center",
alignItems: "center",
shadowColor: "#000",
shadowOpacity: 1,
shadowOffset: {
width: 0,
height: 0,
},
shadowRadius: 20,
}}
>
<Image source={{ uri: item }} style={styles.image} />
</View>
);
}}
/>
</View>
);
};
const styles = StyleSheet.create({
image: {
width: imageW,
height: imageH,
resizeMode: "cover",
borderRadius: 16,
},
});