Repository navigation
Expand file tree
/
Copy pathTimerPagination.tsx
More file actions
105 lines (98 loc) · 2.46 KB
/
Copy pathTimerPagination.tsx
File metadata and controls
105 lines (98 loc) · 2.46 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
97
98
99
100
101
102
103
104
105
import { useCarouselContext } from '@strv/react-native-hero-carousel'
import { StyleSheet, View } from 'react-native'
import Animated, { useAnimatedStyle, withTiming } from 'react-native-reanimated'
import { BlurView } from 'expo-blur'
// Individual pagination dot component
const PaginationDot = ({
index,
hideProgressOnInteraction,
}: {
index: number
total: number
hideProgressOnInteraction: boolean
}) => {
const { scrollValue, timeoutValue, userInteracted } = useCarouselContext()
const progressStyle = useAnimatedStyle(() => {
const isActive = scrollValue.value - 1 >= index && scrollValue.value - 1 < index + 1
const wasActive = scrollValue.value - 1 > index
if ((!isActive && !wasActive) || (hideProgressOnInteraction && userInteracted)) {
return {
width: 0,
}
}
return {
width: `${wasActive ? 100 : timeoutValue.value * 100}%`,
}
})
const dotStyle = useAnimatedStyle(() => {
const isActive = Math.round(scrollValue.value - 1) === index
const opacity = isActive ? withTiming(1) : withTiming(0.5)
return {
opacity,
}
})
return (
<View style={styles.paginationDot}>
<Animated.View style={[styles.dotBackground, dotStyle]} />
<Animated.View style={[styles.dotProgress, progressStyle]} />
</View>
)
}
export const TimerPagination = ({
total,
hideProgressOnInteraction,
}: {
total: number
hideProgressOnInteraction: boolean
}) => {
return (
<BlurView style={styles.paginationContainer}>
{Array.from({ length: total }).map((_, index) => (
<PaginationDot
key={index}
index={index}
total={total}
hideProgressOnInteraction={hideProgressOnInteraction}
/>
))}
</BlurView>
)
}
const styles = StyleSheet.create({
paginationContainer: {
position: 'absolute',
top: 20,
left: 20,
right: 20,
overflow: 'hidden',
flexDirection: 'row',
gap: 8,
borderRadius: 16,
borderWidth: 1,
borderColor: 'rgba(255, 255, 255, 0.05)',
zIndex: 10,
},
paginationDot: {
flex: 1,
height: 3,
backgroundColor: 'rgba(255, 255, 255, 0.3)',
borderRadius: 2,
overflow: 'hidden',
},
dotBackground: {
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
backgroundColor: 'rgba(255, 255, 255, 0.5)',
},
dotProgress: {
position: 'absolute',
top: 0,
left: 0,
bottom: 0,
backgroundColor: 'white',
borderRadius: 2,
},
})