-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.js
More file actions
67 lines (54 loc) · 1.33 KB
/
index.js
File metadata and controls
67 lines (54 loc) · 1.33 KB
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
import React, {Component, PropTypes} from 'react';
import {
View,
StyleSheet,
requireNativeComponent,
} from 'react-native';
class Checkbox extends Component {
constructor() {
super();
this._checkboxComponent = {};
this._onChange = (event) => {
this.props.onChange && this.props.onChange(event);
this.props.onValueChange && this.props.onValueChange(event.nativeEvent.value);
this._checkboxComponent.setNativeProps({on: this.props.value});
}
}
render() {
return (
<View style={this.props.style}>
<CheckboxComponent
{...this.props}
style={styles.checkbox}
ref={(ref) => { this._checkboxComponent = ref; }}
on={this.props.value}
disabled={this.props.disabled}
onChange={this._onChange}
/>
</View>
);
}
}
Checkbox.propTypes = {
...View.propTypes,
/**
* is the checkbox checked. Default false
*/
value: React.PropTypes.bool,
disabled: React.PropTypes.bool,
tintColor: React.PropTypes.string,
};
Checkbox.defaultProps = {
value: false,
disabled: false,
};
const styles = StyleSheet.create({
checkbox: {
height: 32,
width: 32,
},
});
const CheckboxComponent = requireNativeComponent('Checkbox', Checkbox, {
nativeOnly: { onChange: true, on: true }
});
export default Checkbox;