-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathScrollViewOffsetExample.tsx
57 lines (52 loc) · 1.15 KB
/
ScrollViewOffsetExample.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
import React from 'react';
import Animated, {
useScrollViewOffset,
useAnimatedStyle,
useAnimatedRef,
} from 'react-native-reanimated';
import { StyleSheet, Text, View } from 'react-native';
export default function ScrollViewOffsetExample() {
const aref = useAnimatedRef<Animated.ScrollView>();
const scrollHandler = useScrollViewOffset(aref);
useAnimatedStyle(() => {
console.log(scrollHandler.value);
return {};
});
return (
<>
<View style={styles.positionView}>
<Text>Test</Text>
</View>
<View style={styles.divider} />
<Animated.ScrollView
ref={aref}
scrollEventThrottle={16}
horizontal={true}
style={styles.scrollView}>
{[...Array(100)].map((_, i) => (
<Text key={i} style={styles.text}>
{i}
</Text>
))}
</Animated.ScrollView>
</>
);
}
const styles = StyleSheet.create({
positionView: {
margin: 20,
alignItems: 'center',
},
scrollView: {
flex: 1,
width: '100%',
},
text: {
fontSize: 50,
textAlign: 'center',
},
divider: {
backgroundColor: 'black',
height: 1,
},
});