UNPKG

react-native-blitzllama-mmkv

Version:

Blitzllama React Native Library with mmkv

162 lines (161 loc) 5.85 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const react_1 = __importStar(require("react")); const react_native_1 = require("react-native"); const deprecated_react_native_prop_types_1 = require("deprecated-react-native-prop-types"); const prop_types_1 = __importDefault(require("prop-types")); class CheckBox extends react_1.Component { constructor(props) { super(props); } static propTypes = { ...deprecated_react_native_prop_types_1.ViewPropTypes, leftText: prop_types_1.default.string, leftTextView: prop_types_1.default.element, rightText: prop_types_1.default.string, leftTextStyle: prop_types_1.default.oneOfType([ prop_types_1.default.string, prop_types_1.default.number, prop_types_1.default.object, ]), rightTextView: prop_types_1.default.element, rightTextStyle: prop_types_1.default.oneOfType([ prop_types_1.default.string, prop_types_1.default.number, prop_types_1.default.object, ]), checkedImage: prop_types_1.default.element, unCheckedImage: prop_types_1.default.element, onClick: prop_types_1.default.func.isRequired, isChecked: prop_types_1.default.bool.isRequired, isIndeterminate: prop_types_1.default.bool.isRequired, checkBoxColor: prop_types_1.default.string, checkedCheckBoxColor: prop_types_1.default.string, uncheckedCheckBoxColor: prop_types_1.default.string, disabled: prop_types_1.default.bool, }; static defaultProps = { isChecked: false, isIndeterminate: false, leftTextStyle: {}, rightTextStyle: {}, }; onClick() { this.props.onClick(); } _renderLeft() { if (this.props.leftTextView) { return this.props.leftTextView; } if (!this.props.leftText) { return null; } return (<react_native_1.Text style={[styles.leftText, this.props.leftTextStyle]}> {this.props.leftText} </react_native_1.Text>); } _renderRight() { if (this.props.rightTextView) { return this.props.rightTextView; } if (!this.props.rightText) { return null; } return (<react_native_1.Text style={[styles.rightText, this.props.rightTextStyle]}> {this.props.rightText} </react_native_1.Text>); } _renderImage() { if (this.props.isIndeterminate) { return this.props.indeterminateImage ? this.props.indeterminateImage : this.genCheckedImage(); } if (this.props.isChecked) { return this.props.checkedImage ? this.props.checkedImage : this.genCheckedImage(); } else { return this.props.unCheckedImage ? this.props.unCheckedImage : this.genCheckedImage(); } } _getCheckedCheckBoxColor() { return this.props.checkedCheckBoxColor ? this.props.checkedCheckBoxColor : this.props.checkBoxColor; } _getUncheckedCheckBoxColor() { return this.props.uncheckedCheckBoxColor ? this.props.uncheckedCheckBoxColor : this.props.checkBoxColor; } _getTintColor() { return this.props.isChecked ? this._getCheckedCheckBoxColor() : this._getUncheckedCheckBoxColor(); } genCheckedImage() { let source; if (this.props.isIndeterminate) { source = require('./img/ic_indeterminate_check_box.png'); } else { source = this.props.isChecked ? require('./img/ic_check_box.png') : require('./img/ic_check_box_outline_blank.png'); } return <react_native_1.Image source={source} style={{ tintColor: this._getTintColor() }}/>; } render() { return (<react_native_1.TouchableHighlight style={this.props.style} onPress={() => this.onClick()} underlayColor="transparent" disabled={this.props.disabled}> <react_native_1.View style={styles.container}> {this._renderLeft()} {this._renderImage()} {this._renderRight()} </react_native_1.View> </react_native_1.TouchableHighlight>); } } exports.default = CheckBox; const styles = react_native_1.StyleSheet.create({ container: { flexDirection: 'row', alignItems: 'center', }, leftText: { flex: 1, }, rightText: { flex: 1, marginLeft: 10, }, });