-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
76 lines (71 loc) · 2.6 KB
/
App.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
// Inspiration: https://dribbble.com/shots/14139308-Simple-Scroll-Animation
// Illustrations by: SAMji https://dribbble.com/SAMji_illustrator
import React, { useRef } from "react";
import {
StatusBar,
Image,
Animated,
View,
Dimensions,
StyleSheet,
} from "react-native";
const { width } = Dimensions.get("screen");
import styles from "./styles";
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",
];
export default () => {
const scrollX = useRef(new Animated.Value(0)).current;
return (
<View style={styles.carouselContainer}>
<StatusBar hidden />
<View style={StyleSheet.absoluteFillObject}>
{data.map((img, 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: img }}
style={[StyleSheet.absoluteFillObject, { opacity }]}
blurRadius={50}
/>
);
})}
</View>
<Animated.FlatList
data={data}
onScroll={Animated.event(
[{ nativeEvent: { contentOffset: { x: scrollX } } }],
{ useNativeDriver: true }
)}
keyExtractor={(_, index) => index.toString()}
horizontal
pagingEnabled
renderItem={({ item }) => {
return (
<View style={styles.imageContainer}>
<Image
source={{ uri: item }}
style={styles.image}
/>
</View>
);
}}
/>
</View>
);
};