forked from 24ark/react-native-step-indicator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HorizontalStepIndicatorExample.js
176 lines (163 loc) · 5.05 KB
/
HorizontalStepIndicatorExample.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
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
173
174
175
176
import React, { Component } from 'react';
import { AppRegistry,StyleSheet,View, Text } from 'react-native';
import { ViewPager } from 'rn-viewpager';
import StepIndicator from 'react-native-step-indicator';
import MaterialIcon from 'react-native-vector-icons/MaterialIcons';
const PAGES = ['Page 1','Page 2','Page 3','Page 4','Page 5'];
const firstIndicatorStyles = {
stepIndicatorSize: 30,
currentStepIndicatorSize:40,
separatorStrokeWidth: 3,
currentStepStrokeWidth: 5,
separatorFinishedColor: '#4aae4f',
separatorUnFinishedColor: '#a4d4a5',
stepIndicatorFinishedColor: '#4aae4f',
stepIndicatorUnFinishedColor: '#a4d4a5',
stepIndicatorCurrentColor: '#ffffff',
stepIndicatorLabelFontSize: 15,
currentStepIndicatorLabelFontSize: 15,
stepIndicatorLabelCurrentColor: '#000000',
stepIndicatorLabelFinishedColor: '#ffffff',
stepIndicatorLabelUnFinishedColor: 'rgba(255,255,255,0.5)',
labelColor: '#666666',
labelSize: 12,
currentStepLabelColor: '#4aae4f'
}
const secondIndicatorStyles = {
stepIndicatorSize: 30,
currentStepIndicatorSize:40,
separatorStrokeWidth: 2,
currentStepStrokeWidth: 3,
stepStrokeCurrentColor: '#fe7013',
stepStrokeWidth: 3,
stepStrokeFinishedColor: '#fe7013',
stepStrokeUnFinishedColor: '#aaaaaa',
separatorFinishedColor: '#fe7013',
separatorUnFinishedColor: '#aaaaaa',
stepIndicatorFinishedColor: '#fe7013',
stepIndicatorUnFinishedColor: '#ffffff',
stepIndicatorCurrentColor: '#ffffff',
stepIndicatorLabelFontSize: 13,
currentStepIndicatorLabelFontSize: 13,
stepIndicatorLabelCurrentColor: '#fe7013',
stepIndicatorLabelFinishedColor: '#ffffff',
stepIndicatorLabelUnFinishedColor: '#aaaaaa',
labelColor: '#999999',
labelSize: 13,
currentStepLabelColor: '#fe7013'
}
const thirdIndicatorStyles = {
stepIndicatorSize: 25,
currentStepIndicatorSize:30,
separatorStrokeWidth: 2,
currentStepStrokeWidth: 3,
stepStrokeCurrentColor: '#7eaec4',
stepStrokeWidth: 3,
stepStrokeFinishedColor: '#7eaec4',
stepStrokeUnFinishedColor: '#dedede',
separatorFinishedColor: '#7eaec4',
separatorUnFinishedColor: '#dedede',
stepIndicatorFinishedColor: '#7eaec4',
stepIndicatorUnFinishedColor: '#ffffff',
stepIndicatorCurrentColor: '#ffffff',
stepIndicatorLabelFontSize: 0,
currentStepIndicatorLabelFontSize: 0,
stepIndicatorLabelCurrentColor: 'transparent',
stepIndicatorLabelFinishedColor: 'transparent',
stepIndicatorLabelUnFinishedColor: 'transparent',
labelColor: '#999999',
labelSize: 13,
currentStepLabelColor: '#7eaec4'
}
const getStepIndicatorIconConfig = ({ position, stepStatus }) => {
const iconConfig = {
name: 'feed',
color: stepStatus === 'finished' ? '#ffffff' : '#fe7013',
size: 15,
};
switch (position) {
case 0: {
iconConfig.name = 'shopping-cart';
break;
}
case 1: {
iconConfig.name = 'location-on';
break;
}
case 2: {
iconConfig.name = 'assessment';
break;
}
case 3: {
iconConfig.name = 'payment';
break;
}
case 4: {
iconConfig.name = 'track-changes';
break;
}
default: {
break;
}
}
return iconConfig;
};
export default class App extends Component {
constructor() {
super();
this.state = {
currentPage:0
}
}
componentWillReceiveProps(nextProps,nextState) {
if(nextState.currentPage != this.state.currentPage) {
if(this.viewPager) {
this.viewPager.setPage(nextState.currentPage)
}
}
}
render() {
return (
<View style={styles.container}>
<View style={styles.stepIndicator}>
<StepIndicator customStyles={firstIndicatorStyles} currentPosition={this.state.currentPage} labels={["Account","Profile","Band","Membership","Dashboard"]} />
</View>
<View style={styles.stepIndicator}>
<StepIndicator renderStepIndicator={this.renderStepIndicator} customStyles={secondIndicatorStyles} currentPosition={this.state.currentPage} labels={["Cart","Delivery Address","Order Summary","Payment Method","Track"]} />
</View>
<View style={styles.stepIndicator}>
<StepIndicator stepCount={4} customStyles={thirdIndicatorStyles} currentPosition={this.state.currentPage} labels={["Approval","Processing","Shipping","Delivery"]} />
</View>
<ViewPager
style={{flexGrow:1}}
ref={(viewPager) => {this.viewPager = viewPager}}
onPageSelected={(page) => {this.setState({currentPage:page.position})}}
>
{PAGES.map((page) => this.renderViewPagerPage(page))}
</ViewPager>
</View>
);
}
renderViewPagerPage = (data) => {
return(<View style={styles.page}>
<Text>{data}</Text>
</View>)
}
renderStepIndicator = params => (
<MaterialIcon {...getStepIndicatorIconConfig(params)} />
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#ffffff',
},
stepIndicator: {
marginVertical:50,
},
page: {
flex:1,
justifyContent:'center',
alignItems:'center'
}
});