/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow * @format */ 'use strict'; const React = require('react'); const ReactNative = require('react-native'); const {CheckBox, Text, View, StyleSheet} = ReactNative; type BasicState = {| trueCheckBoxIsOn: boolean, falseCheckBoxIsOn: boolean, |}; type BasicProps = $ReadOnly<{||}>; class BasicCheckBoxExample extends React.Component { state = { trueCheckBoxIsOn: true, falseCheckBoxIsOn: false, }; render() { return ( this.setState({falseCheckBoxIsOn: value})} style={styles.checkbox} value={this.state.falseCheckBoxIsOn} /> this.setState({trueCheckBoxIsOn: value})} value={this.state.trueCheckBoxIsOn} /> ); } } type DisabledProps = $ReadOnly<{||}>; class DisabledCheckBoxExample extends React.Component { render() { return ( ); } } type EventProps = $ReadOnly<{||}>; type EventState = {| eventCheckBoxIsOn: boolean, eventCheckBoxRegressionIsOn: boolean, |}; class EventCheckBoxExample extends React.Component { state = { eventCheckBoxIsOn: false, eventCheckBoxRegressionIsOn: true, }; render() { return ( this.setState({eventCheckBoxIsOn: value})} style={styles.checkbox} value={this.state.eventCheckBoxIsOn} /> this.setState({eventCheckBoxIsOn: value})} style={styles.checkbox} value={this.state.eventCheckBoxIsOn} /> {this.state.eventCheckBoxIsOn ? 'On' : 'Off'} this.setState({eventCheckBoxRegressionIsOn: value}) } style={styles.checkbox} value={this.state.eventCheckBoxRegressionIsOn} /> this.setState({eventCheckBoxRegressionIsOn: value}) } style={styles.checkbox} value={this.state.eventCheckBoxRegressionIsOn} /> {this.state.eventCheckBoxRegressionIsOn ? 'On' : 'Off'} ); } } const styles = StyleSheet.create({ container: { flexDirection: 'row', justifyContent: 'space-around', }, checkbox: { marginBottom: 10, }, }); exports.title = ''; exports.displayName = 'CheckBoxExample'; exports.description = 'Native boolean input'; exports.examples = [ { title: 'CheckBoxes can be set to true or false', render(): React.Element { return ; }, }, { title: 'CheckBoxes can be disabled', render(): React.Element { return ; }, }, { title: 'Change events can be detected', render(): React.Element { return ; }, }, { title: 'CheckBoxes are controlled components', render(): React.Element { return ; }, }, ];