-
Notifications
You must be signed in to change notification settings - Fork 312
/
VerticalStepIndicator.tsx
99 lines (93 loc) · 2.59 KB
/
VerticalStepIndicator.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
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
import * as React from 'react';
import { StyleSheet, View, Text, FlatList } from 'react-native';
import StepIndicator from 'react-native-step-indicator';
import dummyData from './data';
const stepIndicatorStyles = {
stepIndicatorSize: 30,
currentStepIndicatorSize: 40,
separatorStrokeWidth: 3,
currentStepStrokeWidth: 5,
stepStrokeCurrentColor: '#fe7013',
separatorFinishedColor: '#fe7013',
separatorUnFinishedColor: '#aaaaaa',
stepIndicatorFinishedColor: '#fe7013',
stepIndicatorUnFinishedColor: '#aaaaaa',
stepIndicatorCurrentColor: '#ffffff',
stepIndicatorLabelFontSize: 15,
currentStepIndicatorLabelFontSize: 15,
stepIndicatorLabelCurrentColor: '#000000',
stepIndicatorLabelFinishedColor: '#ffffff',
stepIndicatorLabelUnFinishedColor: 'rgba(255,255,255,0.5)',
labelColor: '#666666',
labelSize: 15,
currentStepLabelColor: '#fe7013',
};
export default function VerticalStepIndicator() {
const [currentPage, setCurrentPage] = React.useState<number>(0);
const viewabilityConfig = React.useRef({ itemVisiblePercentThreshold: 40 })
.current;
const renderPage = (rowData: any) => {
const item = rowData.item;
return (
<View style={styles.rowItem}>
<Text style={styles.title}>{item.title}</Text>
<Text style={styles.body}>{item.body}</Text>
</View>
);
};
const onViewableItemsChanged = React.useCallback(({ viewableItems }) => {
const visibleItemsCount = viewableItems.length;
if (visibleItemsCount !== 0) {
setCurrentPage(viewableItems[visibleItemsCount - 1].index);
}
}, []);
return (
<View style={styles.container}>
<View style={styles.stepIndicator}>
<StepIndicator
customStyles={stepIndicatorStyles}
stepCount={6}
direction="vertical"
currentPosition={currentPage}
labels={dummyData.data.map((item) => item.title)}
/>
</View>
<FlatList
style={{ flexGrow: 1 }}
data={dummyData.data}
renderItem={renderPage}
onViewableItemsChanged={onViewableItemsChanged}
viewabilityConfig={viewabilityConfig}
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
backgroundColor: '#ffffff',
},
stepIndicator: {
marginVertical: 50,
paddingHorizontal: 20,
},
rowItem: {
flex: 3,
paddingVertical: 20,
},
title: {
flex: 1,
fontSize: 20,
color: '#333333',
paddingVertical: 16,
fontWeight: '600',
},
body: {
flex: 1,
fontSize: 15,
color: '#606060',
lineHeight: 24,
marginRight: 8,
},
});