-
Notifications
You must be signed in to change notification settings - Fork 465
Expand file tree
/
Copy pathControlPanel.tsx
More file actions
172 lines (170 loc) · 4.14 KB
/
ControlPanel.tsx
File metadata and controls
172 lines (170 loc) · 4.14 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import React, { useCallback } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Button } from '../Button';
import { ProgressBar } from '../ProgressBar';
import type { NavigationPanelProps } from './types';
export function ControlsPanel({
activePage,
isAnimated,
pages,
scrollState,
scrollEnabled,
progress,
disablePagesAmountManagement,
overdrag,
setPage,
addPage,
removePage,
toggleScroll,
toggleAnimation,
toggleOverdrag,
}: NavigationPanelProps) {
const firstPage = useCallback(() => setPage(0), [setPage]);
const prevPage = useCallback(
() => setPage(activePage - 1),
[activePage, setPage]
);
const nextPage = useCallback(
() => setPage(activePage + 1),
[setPage, activePage]
);
const lastPage = useCallback(
() => setPage(pages.length - 1),
[pages.length, setPage]
);
return (
<>
<View style={styles.buttons}>
<Button
testID="scroll-enabled-button"
text={scrollEnabled ? 'Scroll Enabled' : 'Scroll Disabled'}
onPress={toggleScroll}
/>
<Button
style={styles.buttonAdjustment}
text={overdrag ? 'Overdrag Enabled' : 'Overdrag Disabled'}
onPress={() => toggleOverdrag()}
/>
</View>
{!disablePagesAmountManagement ? (
<View style={styles.buttons}>
<Button
testID="add-page-button"
text="Add new page"
onPress={addPage}
/>
<Button
testID="remove-page-button"
text="Remove last page"
onPress={removePage}
/>
</View>
) : null}
<View style={styles.buttons}>
<Button
testID="add-page-button"
text={isAnimated ? 'Turn off animations' : 'Turn animations back on'}
onPress={toggleAnimation}
/>
<View style={styles.scrollState}>
<Text style={styles.scrollStateText}>
ScrollState[ {scrollState} ]
</Text>
</View>
</View>
<View style={styles.buttons}>
<Button
testID="start-page-button"
text="Start"
disabled={activePage === 0}
onPress={firstPage}
/>
<Button
testID="prev-page-button"
text="Prev"
disabled={activePage === 0}
onPress={prevPage}
/>
<Button
testID="next-page-button"
text="Next"
disabled={activePage === pages.length - 1}
onPress={nextPage}
/>
<Button
testID="last-page-button"
text="Last"
disabled={activePage === pages.length - 1}
onPress={lastPage}
/>
</View>
<View style={styles.progress}>
<Text style={styles.buttonText}>
Page {activePage + 1} / {pages.length}{' '}
</Text>
<ProgressBar numberOfPages={pages.length} progress={progress} />
</View>
</>
);
}
const styles = StyleSheet.create({
toggleVisibilityButtonContainer: {
position: 'absolute',
left: 8,
bottom: '100%',
flexDirection: 'row',
},
toggleVisibilityButton: {
paddingHorizontal: 8,
paddingVertical: 4,
backgroundColor: '#000',
alignItems: 'center',
justifyContent: 'center',
borderTopLeftRadius: 5,
borderTopRightRadius: 5,
borderWidth: 1,
borderColor: '#000',
},
toggleVisibilityButtonActive: {
backgroundColor: '#fff',
},
toggleVisibilityText: {
color: '#fff',
fontSize: 20,
},
toggleVisibilityTextActive: {
color: '#000',
},
buttons: {
flexDirection: 'row',
backgroundColor: 'black',
alignItems: 'center',
justifyContent: 'space-between',
},
hiddenContainer: {
height: 0,
overflow: 'hidden',
},
buttonAdjustment: {
flex: 1,
},
progress: {
flexDirection: 'row',
height: 40,
backgroundColor: 'black',
justifyContent: 'space-between',
alignItems: 'center',
},
buttonText: {
color: 'white',
paddingHorizontal: 20,
},
scrollState: {
flex: 1,
justifyContent: 'flex-end',
},
scrollStateText: {
color: '#99d1b7',
textAlign: 'center',
},
});