-
-
Notifications
You must be signed in to change notification settings - Fork 338
/
Copy pathindex.tsx
97 lines (88 loc) · 2.21 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
import * as React from "react";
import { View, Text } from "react-native";
import Animated, { Easing } from "react-native-reanimated";
import Carousel from "react-native-reanimated-carousel";
import { window } from "../../constants";
const PAGE_WIDTH = window.width / 2;
function ReactionContainer(props: {
text: string
children: (
text: React.ReactElement,
layout?: { width: number }
) => React.ReactElement
}) {
const [width, setWidth] = React.useState<number>();
const [layout, setLayout] = React.useState<{ width: number }>();
React.useEffect(() => {
if (typeof width === "number")
setLayout({ width });
}, [width]);
React.useEffect(() => {
setLayout(undefined);
}, [props.text]);
const text = (
<Animated.View
style={[
{
flexWrap: "wrap",
width: layout?.width,
},
]}
>
<Text
onLayout={({ nativeEvent }) => {
if (typeof layout === "undefined")
setWidth(nativeEvent.layout.width);
}}
>
{props.text}
</Text>
</Animated.View>
);
return React.cloneElement(props.children(text, layout), {
key: props.text,
});
}
function Index() {
return (
<ReactionContainer text="一二三四五六七八九十">
{(text, layout) => {
return (
<View
style={{
alignItems: "center",
flex: 1,
marginTop: 72,
}}
>
<Carousel
width={layout?.width ?? PAGE_WIDTH}
height={30}
style={[
{
width: 200,
},
]}
snapEnabled={false}
pagingEnabled={false}
loop
autoPlay
withAnimation={{
type: "timing",
config: {
duration: 10000,
easing: Easing.linear,
},
}}
autoPlayInterval={0}
data={[...new Array(6).keys()]}
renderItem={() => text}
enabled={false}
/>
</View>
);
}}
</ReactionContainer>
);
}
export default Index;