-
Notifications
You must be signed in to change notification settings - Fork 465
Expand file tree
/
Copy pathhook.tsx
More file actions
80 lines (76 loc) · 1.95 KB
/
hook.tsx
File metadata and controls
80 lines (76 loc) · 1.95 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
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { usePagerView } 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 HookExample() {
const {
AnimatedPagerView,
ref,
activePage,
onPageScroll,
onPageSelected,
onPageScrollStateChanged,
scrollState,
progress,
} = usePagerView({ pagesAmount: PAGES.length });
return (
<View style={styles.container}>
<AnimatedPagerView
ref={ref}
style={styles.pager}
initialPage={0}
onPageScroll={onPageScroll}
onPageSelected={onPageSelected}
onPageScrollStateChanged={onPageScrollStateChanged}
>
{PAGES.map((page) => (
<View
key={page.key}
style={[styles.page, { backgroundColor: page.color }]}
>
<Text style={styles.title}>{page.title}</Text>
</View>
))}
</AnimatedPagerView>
<View style={styles.info}>
<Text style={styles.label}>usePagerView state:</Text>
<Text style={styles.value}>
activePage: {activePage} | scrollState: {scrollState}
</Text>
<Text style={styles.value}>
progress: pos={progress.position} off={progress.offset.toFixed(4)}
</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' },
info: {
padding: 16,
backgroundColor: '#1a1a2e',
},
label: {
fontSize: 12,
fontWeight: '600',
color: '#888',
fontFamily: 'monospace',
},
value: {
fontSize: 14,
color: '#fff',
fontFamily: 'monospace',
marginTop: 4,
},
});