-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathMethodsWithLoop.tsx
138 lines (134 loc) · 3.68 KB
/
MethodsWithLoop.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
import React from "react";
import {
AccessibilityInfo,
Button,
Platform,
Text,
TextStyle,
View,
ViewStyle
} from "react-native";
import Carousel from "../../src/index";
const styles = {
slide1: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#a3c9a8"
} as ViewStyle,
slide2: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#84b59f"
} as ViewStyle,
slide3: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#69a297"
} as ViewStyle,
text: {
color: "#1f2d3d",
opacity: 0.7,
fontSize: 48,
fontWeight: "bold"
} as TextStyle
};
export class MethodsWithLoop extends React.PureComponent {
carousel: Carousel | null;
constructor(props: {}) {
super(props);
this.carousel = null;
}
render(): JSX.Element {
return (
<View style={{ flex: 1, flexDirection: "column" }}>
<Carousel
loop={true}
ref={(carousel): void => {
this.carousel = carousel;
}}
height={200}
autoplayInterval={3000}
onIndexChanged={({ index, total }): void => {
if (Platform.OS === "ios") {
const page = index + 1;
AccessibilityInfo.announceForAccessibility(
`Changed to page ${page}/${total}`
);
}
}}
>
<View style={styles.slide1} testID="slide-1">
<Text style={styles.text}>1</Text>
</View>
<View style={styles.slide2} testID="slide-2">
<Text style={styles.text}>2</Text>
</View>
<View style={styles.slide3} testID="slide-3">
<Text style={styles.text}>3</Text>
</View>
<View style={styles.slide1} testID="slide-4">
<Text style={styles.text}>4</Text>
</View>
<View style={styles.slide2} testID="slide-5">
<Text style={styles.text}>5</Text>
</View>
<View style={styles.slide3} testID="slide-6">
<Text style={styles.text}>6</Text>
</View>
</Carousel>
<View style={{ paddingTop: 20 }}>
<Button
testID="scroll-to-next"
title="scroll to next page"
onPress={(): void | null =>
this.carousel && this.carousel.scrollToNext()
}
/>
<Button
testID="scroll-to-prev"
title="scroll to previous page"
onPress={(): void | null =>
this.carousel && this.carousel.scrollToPrev()
}
/>
<Button
testID="scroll-to-page-4"
title="scroll to page 4"
onPress={(): void | null =>
this.carousel && this.carousel.scrollToIndex({ index: 3 })
}
/>
<Button
title="scroll +2 pages"
onPress={(): void | null =>
this.carousel && this.carousel.scrollBy({ index: 2 })
}
/>
<Button
title="scroll -2 pages"
onPress={(): void | null =>
this.carousel && this.carousel.scrollBy({ index: -2 })
}
/>
<Button
testID="start-autoplay"
title="start autoplay"
onPress={(): void | null =>
this.carousel && this.carousel.startAutoplay()
}
/>
<Button
testID="stop-autoplay"
title="stop autoplay"
onPress={(): void | null =>
this.carousel && this.carousel.stopAutoplay()
}
/>
</View>
</View>
);
}
}