-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLoopTabBar.js
54 lines (47 loc) · 986 Bytes
/
LoopTabBar.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
import React from 'react';
import PropTypes from 'prop-types';
import {
View,
} from 'react-native';
export default class LoopTabBar extends React.Component {
static propTypes = {
tabs: PropTypes.array,
activeTab: PropTypes.number,
};
static defaultProps = {
tabs: [],
activeTab: 0,
};
constructor(props) {
super(props);
const {
tabs,
} = this.props;
const newTabs = [...tabs];
newTabs.pop();
newTabs.shift();
this.pages = tabs.length;
this.newTabs = newTabs;
}
render() {
const {
activeTab,
} = this.props;
const newActiveTab = activeTab === this.pages - 1
? 0
: activeTab === 0
? this.pages - 2
: activeTab - 1;
const newChildren = React.cloneElement(this.props.children, {
...this.props,
activeTab: newActiveTab,
initialPage: 0,
tabs: this.newTabs,
});
return (
<View>
{newChildren}
</View>
);
}
}