-
Notifications
You must be signed in to change notification settings - Fork 4
/
Toggle.js
48 lines (37 loc) · 1 KB
/
Toggle.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
import React, {Component, PropTypes} from 'react';
import {
requireNativeComponent,
View
} from 'react-native';
let viewPropTypes = View.propTypes;
class Toggle extends Component{
static displayName = 'Toggle';
static propTypes = {
...viewPropTypes,
hidden: PropTypes.bool
};
static defaultProps = {
hidden: false
};
constructor() {
super(...arguments);
this.state = {
hasBeenSelected: !this.props.hidden
};
}
componentWillReceiveProps = nextProps => {
if (nextProps.hidden !== this.props.hidden && !this.state.hasBeenSelected) {
this.setState({
hasBeenSelected: true
});
}
};
shouldComponentUpdate = nextProps => {
return !nextProps.hidden || nextProps.hidden !== this.props.hidden;
};
render() {
return <RCTToggle {...this.props} />;
}
}
let RCTToggle = requireNativeComponent('RCTToggle', Toggle);
export default Toggle;