forked from dohooo/react-native-reanimated-carousel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
69 lines (61 loc) · 1.7 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
import * as React from "react";
import { View } from "react-native";
import { interpolate } from "react-native-reanimated";
import Carousel from "react-native-reanimated-carousel";
import type { TAnimationStyle } from "../../../../src/layouts/BaseLayout";
import { SBItem } from "../../components/SBItem";
import { ElementsText, window } from "../../constants";
import { useToggleButton } from "../../hooks/useToggleButton";
const scale = 0.7;
const PAGE_WIDTH = window.width * scale;
const PAGE_HEIGHT = 240 * scale;
function Index() {
const AutoPLay = useToggleButton({
defaultValue: false,
buttonTitle: ElementsText.AUTOPLAY,
});
const animationStyle: TAnimationStyle = React.useCallback(
(value: number) => {
"worklet";
const zIndex = interpolate(value, [-1, 0, 1], [10, 20, 30]);
const rotateZ = `${interpolate(
value,
[-1, 0, 1],
[-45, 0, 45],
)}deg`;
const translateX = interpolate(
value,
[-1, 0, 1],
[-window.width, 0, window.width],
);
return {
transform: [{ rotateZ }, { translateX }],
zIndex,
};
},
[],
);
return (
<View style={{ flex: 1 }}>
<Carousel
loop
style={{
width: window.width,
height: 240,
justifyContent: "center",
alignItems: "center",
}}
width={PAGE_WIDTH}
height={PAGE_HEIGHT}
data={[...new Array(6).keys()]}
renderItem={({ index }) => {
return <SBItem key={index} index={index} />;
}}
autoPlay={AutoPLay.status}
customAnimation={animationStyle}
/>
{AutoPLay.button}
</View>
);
}
export default Index;