forked from dohooo/react-native-reanimated-carousel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
127 lines (123 loc) · 4.25 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
import * as React from 'react';
import { View } from 'react-native-ui-lib';
import Carousel from 'react-native-reanimated-carousel';
import { SBItem } from '../components/SBItem';
import SButton from '../components/SButton';
import { ElementsText } from '../constants';
import { FadeInRight } from 'react-native-reanimated';
function Index() {
const [mode, setMode] = React.useState<any>('horizontal-stack');
const [snapDirection, setSnapDirection] = React.useState<'left' | 'right'>(
'left'
);
const [pagingEnabled, setPagingEnabled] = React.useState<boolean>(true);
const [snapEnabled, setSnapEnabled] = React.useState<boolean>(true);
const [loop, setLoop] = React.useState<boolean>(true);
const [autoPlay, setAutoPlay] = React.useState<boolean>(false);
const [autoPlayReverse, setAutoPlayReverse] =
React.useState<boolean>(false);
const data = React.useRef<number[]>([...new Array(6).keys()]).current;
const viewCount = 5;
return (
<View style={{ flex: 1 }}>
<Carousel
style={{
width: '100%',
height: 240,
alignItems: 'center',
justifyContent: 'center',
}}
width={280}
height={210}
pagingEnabled={pagingEnabled}
snapEnabled={snapEnabled}
mode={mode}
loop={loop}
autoPlay={autoPlay}
autoPlayReverse={autoPlayReverse}
data={data}
modeConfig={{
snapDirection,
stackInterval: mode === 'vertical-stack' ? 8 : 18,
}}
customConfig={() => ({ type: 'positive', viewCount })}
renderItem={({ index }) => (
<SBItem
index={index}
key={index}
entering={FadeInRight.delay(
(viewCount - index) * 100
).duration(200)}
/>
)}
/>
<View
style={{
flexDirection: 'row',
flexWrap: 'wrap',
justifyContent: 'space-evenly',
}}
>
<SButton
onPress={() => {
setMode('horizontal-stack');
}}
>
{'horizontal-stack'}
</SButton>
<SButton
onPress={() => {
setMode('vertical-stack');
}}
>
{'vertical-stack'}
</SButton>
<SButton
onPress={() => {
setAutoPlay(!autoPlay);
}}
>
{`${ElementsText.AUTOPLAY}:${autoPlay}`}
</SButton>
<SButton
onPress={() => {
setAutoPlayReverse(!autoPlayReverse);
}}
>
{`autoPlayReverse:${autoPlayReverse}`}
</SButton>
<SButton
onPress={() => {
setLoop(!loop);
}}
>
{`loop:${loop}`}
</SButton>
<SButton
onPress={() => {
setSnapDirection(
snapDirection === 'left' ? 'right' : 'left'
);
}}
>
{snapDirection}
</SButton>
<SButton
onPress={() => {
setPagingEnabled(!pagingEnabled);
}}
>
{`pagingEnabled:${pagingEnabled}`}
</SButton>
<SButton
onPress={() => {
setSnapEnabled(!snapEnabled);
}}
>
{`snapEnabled:${snapEnabled}`}
</SButton>
</View>
</View>
);
}
export default Index;