forked from mikemonteith/react-native-android-checkbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (51 loc) · 1.22 KB
/
index.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
'use strict';
import React, { Component } from 'react';
import {
View,
StyleSheet,
requireNativeComponent,
} from 'react-native';
class Checkbox extends React.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}
onChange={this._onChange}
/>
</View>
);
}
}
Checkbox.propTypes = {
...View.propTypes,
/**
* is the checkbox checked. Default false
*/
value: React.PropTypes.bool,
};
Checkbox.defaultProps = {
value: false,
};
var styles = StyleSheet.create({
checkbox: {
height: 32,
width: 32,
},
});
var CheckboxComponent = requireNativeComponent('Checkbox', Checkbox, {
nativeOnly: { onChange: true, on: true }
});
module.exports = Checkbox;