forked from dohooo/react-native-reanimated-carousel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
161 lines (151 loc) · 4.56 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import * as React from "react";
import { Text, View, Image } from "react-native";
import { interpolate } from "react-native-reanimated";
import Carousel, { TAnimationStyle } from "react-native-reanimated-carousel";
import { faker } from "@faker-js/faker";
import { BlurView } from "expo-blur";
import { window } from "../../constants";
function Index() {
const headerHeight = 100;
const scale = 0.9;
const RIGHT_OFFSET = window.width * (1 - scale);
const ITEM_WIDTH = window.width * scale;
const ITEM_HEIGHT = 120;
const PAGE_HEIGHT = window.height - headerHeight;
const PAGE_WIDTH = window.width;
const animationStyle: TAnimationStyle = React.useCallback(
(value: number) => {
"worklet";
const translateY = interpolate(
value,
[-1, 0, 1],
[-ITEM_HEIGHT, 0, ITEM_HEIGHT],
);
const right = interpolate(
value,
[-1, -0.2, 1],
[RIGHT_OFFSET / 2, RIGHT_OFFSET, RIGHT_OFFSET / 3],
);
return {
transform: [{ translateY }],
right,
};
},
[RIGHT_OFFSET],
);
return (
<View style={{ flex: 1 }}>
<Image
source={{
uri:
`${faker.image.nature(PAGE_WIDTH, PAGE_HEIGHT)
}?random=${
Math.random()}`,
}}
style={{
width: PAGE_WIDTH,
height: PAGE_HEIGHT,
position: "absolute",
}}
/>
<BlurView
intensity={80}
tint="dark"
style={{
width: PAGE_WIDTH,
height: PAGE_HEIGHT,
position: "absolute",
}}
/>
<Carousel
loop
vertical
style={{
justifyContent: "center",
width: PAGE_WIDTH,
height: PAGE_HEIGHT,
}}
width={ITEM_WIDTH}
pagingEnabled={false}
height={ITEM_HEIGHT}
data={[...new Array(10).keys()]}
renderItem={({ index }) => {
return (
<View key={index} style={{ flex: 1, padding: 10 }}>
<View
style={{
alignItems: "flex-start",
flex: 1,
justifyContent: "space-between",
flexDirection: "row",
borderRadius: 20,
}}
>
<View
style={{
flexDirection: "row",
alignItems: "center",
}}
>
<Image
style={{
width: 20,
height: 20,
borderRadius: 10,
marginRight: 5,
}}
source={{
uri:
`${faker.image.animals(20, 20)
}?random=${
Math.random()}`,
}}
/>
<Text
numberOfLines={1}
style={{
maxWidth: ITEM_WIDTH * 0.3 - 40,
color: "white",
}}
>
{faker.animal.dog()}
</Text>
</View>
<View
style={{
width: ITEM_WIDTH * 0.6,
height: ITEM_HEIGHT - 20,
borderRadius: 10,
overflow: "hidden",
}}
>
<Image
style={{
width: ITEM_WIDTH * 0.6,
height: ITEM_HEIGHT - 20,
borderRadius: 10,
marginRight: 5,
}}
source={{
uri:
`${faker.image.nature(
Math.round(
ITEM_WIDTH * 0.6,
),
ITEM_HEIGHT - 20,
)
}?random=${
Math.random()}`,
}}
/>
</View>
</View>
</View>
);
}}
customAnimation={animationStyle}
/>
</View>
);
}
export default Index;