-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
110 lines (100 loc) · 2.21 KB
/
App.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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
*/
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import Carousel from './src';
import Animated, {
interpolate,
SharedValue,
useAnimatedStyle,
} from 'react-native-reanimated';
const CARD_WIDTH = 360;
const RenderItem = React.memo(
({
item,
animationValue: scrollX,
index,
}: {
item: string;
index: number;
animationValue: SharedValue<number>;
}) => {
const animStyleBanner = useAnimatedStyle(() => {
const inputRange = [
(index - 1) * CARD_WIDTH,
index * CARD_WIDTH,
(index + 1) * CARD_WIDTH,
];
const scale = interpolate(
Math.abs(scrollX.value),
inputRange,
[0.8, 1, 0.8],
);
const translateX = interpolate(
Math.abs(scrollX.value),
inputRange,
[-32, 0, 32],
);
const transFormX = {
transform: [{ scale }, { translateX }],
};
return transFormX;
}, [scrollX.value]);
return (
<Animated.View
style={[styles.box, { backgroundColor: item }, animStyleBanner]}
/>
);
},
() => true,
);
const list = ['#59B4C3', '#40A2E3', '#FDBF60', '#EFF396', '#9F70FD', '#74E291'];
const CarouselMemo = React.memo(
() => {
return (
<Carousel
data={list}
renderItem={({ item, index, animationValue }) => (
<RenderItem
item={item}
index={index}
animationValue={animationValue}
/>
)}
itemSize={CARD_WIDTH}
loop
autoPlay
autoPlayInterval={1500}
/>
);
},
() => true,
);
function App(): React.JSX.Element {
const [state, setstate] = React.useState(true);
return (
<View style={{ flex: 1, marginHorizontal: 16 }}>
<Text
style={{
fontSize: 50,
marginVertical: 100,
textAlign: 'center',
}}
onPress={() => setstate(prev => !prev)}>
{'Text state: ' + state.valueOf()}
</Text>
<CarouselMemo />
</View>
);
}
export default App;
const styles = StyleSheet.create({
box: {
width: CARD_WIDTH,
height: 200,
},
});