-
Notifications
You must be signed in to change notification settings - Fork 0
/
TabIndicators.js
106 lines (90 loc) · 2.67 KB
/
TabIndicators.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
/**
* Created by ananya.chandra on 23/03/18.
*/
import React from 'react';
import {View, StyleSheet, Animated} from 'react-native';
import PropTypes from 'prop-types';
let size;
class TabIndicators extends React.Component {
static propTypes = {
tabs: PropTypes.array.isRequired,
activeColor: PropTypes.string,
inactiveColor: PropTypes.string,
tabIndicatorsContainer: PropTypes.object,
tabIndicatorsView: PropTypes.object,
/**
* Height and width of the default circular indicator.
* Default = 7.
* Shape can be changed using tabIndicatorsView.
*/
size: PropTypes.number,
/**
* Passing this won't cause initial jerk.
*/
openingTabIndex: PropTypes.number
};
constructor(props) {
super(props);
this.updateOffset = this.updateOffset.bind(this);
this._tabs = props.tabs;
size = props.size;
this._defaultTabIndicatorsView = {
height: size,
width: size,
borderRadius: size,
margin: size/2
};
this.state = {
_offset: new Animated.Value(props.openingTabIndex),
activeColor: props.activeColor,
inactiveColor: props.inactiveColor
}
}
updateOffset(offset) {
this.state._offset.setValue(offset);
}
render() {
return (
<View style={[styles.tabIndicatorsContainer, this.props.tabIndicatorsContainer]}>
{this._tabs.map((item, index) => {
let color = this.state._offset.interpolate({
inputRange: [
index-100,
index-1,
index,
index+1,
index+100
],
outputRange: [
this.props.inactiveColor,
this.props.inactiveColor,
this.props.activeColor,
this.props.inactiveColor,
this.props.inactiveColor
]
});
return (
<Animated.View style={[this._defaultTabIndicatorsView, this.props.tabIndicatorsView, {backgroundColor: color}]}/>
);
})}
</View>
);
}
}
TabIndicators.defaultProps = {
activeColor: 'black',
inactiveColor: 'lightgray',
size: 7
};
const styles = StyleSheet.create({
tabIndicatorsContainer: {
flexDirection: 'row',
height: 42,
width: 50,
alignSelf: 'center',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'transparent'
}
});
export default TabIndicators;