forked from dohooo/react-native-reanimated-carousel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
112 lines (101 loc) · 2.62 KB
/
index.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
109
110
111
112
import * as React from "react";
import type { ImageSourcePropType } from "react-native";
import { Image, StyleSheet, View } from "react-native";
import Animated, {
interpolate,
useAnimatedStyle,
} from "react-native-reanimated";
import Carousel from "react-native-reanimated-carousel";
import { BlurView as _BlurView } from "expo-blur";
import { parallaxLayout } from "./parallax";
import SButton from "../../components/SButton";
import { ElementsText, window } from "../../constants";
import { fruitItems } from "../../utils/items";
const BlurView = Animated.createAnimatedComponent(_BlurView);
const PAGE_WIDTH = window.width / 2;
function Index() {
const [isAutoPlay, setIsAutoPlay] = React.useState(false);
return (
<View style={{ flex: 1 }}>
<Carousel
loop={true}
autoPlay={isAutoPlay}
style={{
width: window.width,
height: 240,
justifyContent: "center",
alignItems: "center",
}}
width={PAGE_WIDTH}
data={[...fruitItems, ...fruitItems]}
renderItem={({ item, index, animationValue }) => {
return (
<CustomItem
key={index}
source={item}
animationValue={animationValue}
/>
);
}}
customAnimation={parallaxLayout(
{
size: PAGE_WIDTH,
vertical: false,
},
{
parallaxScrollingScale: 1,
parallaxAdjacentItemScale: 0.5,
parallaxScrollingOffset: 40,
},
)}
scrollAnimationDuration={1200}
/>
<SButton
onPress={() => {
setIsAutoPlay(!isAutoPlay);
}}
>
{ElementsText.AUTOPLAY}:{`${isAutoPlay}`}
</SButton>
</View>
);
}
interface ItemProps {
source: ImageSourcePropType
animationValue: Animated.SharedValue<number>
}
const CustomItem: React.FC<ItemProps> = ({ source, animationValue }) => {
const maskStyle = useAnimatedStyle(() => {
const opacity = interpolate(
animationValue.value,
[-1, 0, 1],
[1, 0, 1],
);
return {
opacity,
};
}, [animationValue]);
return (
<View
style={{
flex: 1,
borderRadius: 10,
overflow: "hidden",
justifyContent: "center",
alignItems: "center",
}}
>
<Image
source={source}
resizeMode={"contain"}
style={{ width: "80%", height: "80%" }}
/>
<BlurView
intensity={50}
pointerEvents="none"
style={[StyleSheet.absoluteFill, maskStyle]}
/>
</View>
);
};
export default Index;