-
Notifications
You must be signed in to change notification settings - Fork 465
Expand file tree
/
Copy pathevents.tsx
More file actions
96 lines (90 loc) · 2.53 KB
/
events.tsx
File metadata and controls
96 lines (90 loc) · 2.53 KB
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
import React, { useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import PagerView from 'react-native-pager-view';
const PAGES = [
{ key: '1', title: 'Page 1', color: '#ff6b6b' },
{ key: '2', title: 'Page 2', color: '#4ecdc4' },
{ key: '3', title: 'Page 3', color: '#45b7d1' },
];
export default function EventsExample() {
const [scrollState, setScrollState] = useState('idle');
const [selectedPage, setSelectedPage] = useState(0);
const [scrollProgress, setScrollProgress] = useState({
position: 0,
offset: 0,
});
return (
<View style={styles.container}>
<PagerView
style={styles.pager}
initialPage={0}
onPageScroll={(e) =>
setScrollProgress({
position: e.nativeEvent.position,
offset: e.nativeEvent.offset,
})
}
onPageSelected={(e) => setSelectedPage(e.nativeEvent.position)}
onPageScrollStateChanged={(e) =>
setScrollState(e.nativeEvent.pageScrollState)
}
>
{PAGES.map((page) => (
<View
key={page.key}
style={[styles.page, { backgroundColor: page.color }]}
>
<Text style={styles.title}>{page.title}</Text>
</View>
))}
</PagerView>
<View style={styles.events}>
<Text style={styles.label}>onPageScroll</Text>
<Text style={styles.value}>
position: {scrollProgress.position} | offset:{' '}
{scrollProgress.offset.toFixed(4)}
</Text>
<Text style={styles.label}>onPageSelected</Text>
<Text style={styles.value}>position: {selectedPage}</Text>
<Text style={styles.label}>onPageScrollStateChanged</Text>
<Text
style={[
styles.value,
scrollState === 'dragging' && styles.dragging,
scrollState === 'settling' && styles.settling,
]}
>
{scrollState}
</Text>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: { flex: 1 },
pager: { flex: 1 },
page: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
title: { fontSize: 32, fontWeight: 'bold', color: '#fff' },
events: {
padding: 16,
backgroundColor: '#1a1a2e',
},
label: {
fontSize: 12,
fontWeight: '600',
color: '#888',
marginTop: 8,
fontFamily: 'monospace',
},
value: {
fontSize: 16,
color: '#fff',
fontFamily: 'monospace',
},
dragging: { color: '#ff6b6b' },
settling: { color: '#ffd93d' },
});