forked from 24ark/react-native-step-indicator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVerticalStepIndicatorExample.js
107 lines (99 loc) · 2.68 KB
/
VerticalStepIndicatorExample.js
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
import React, { Component } from 'react';
import { View, Text, StyleSheet, ListView, 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 class VerticalStepIndicator extends Component {
constructor() {
super();
this.state = {
currentPage:0
};
this.viewabilityConfig = {itemVisiblePercentThreshold: 40}
}
render() {
return (
<View style={styles.container}>
<View style={styles.stepIndicator}>
<StepIndicator
customStyles={stepIndicatorStyles}
stepCount={6}
direction='vertical'
currentPosition={this.state.currentPage}
labels={dummyData.data.map(item => item.title)}
/>
</View>
<FlatList
style={{flexGrow:1}}
data={dummyData.data}
renderItem={this.renderPage}
onViewableItemsChanged={this.onViewableItemsChanged}
viewabilityConfig={this.viewabilityConfig}
/>
</View>
);
}
renderPage = (rowData) => {
const item = rowData.item
return (
<View style={styles.rowItem}>
<Text style={styles.title}>{item.title}</Text>
<Text style={styles.body}>{item.body}</Text>
</View>
)
}
onViewableItemsChanged = ({ viewableItems, changed }) => {
const visibleItemsCount = viewableItems.length;
if(visibleItemsCount != 0) {
this.setState({currentPage:viewableItems[visibleItemsCount-1].index})
};
}
}
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
}
});