/* @flow */ import * as React from 'react'; import { View, StyleSheet, Platform } from 'react-native'; import { Paragraph, Switch, Colors, TouchableRipple, withTheme, } from 'react-native-paper'; import type { Theme } from 'react-native-paper/types'; type Props = { theme: Theme, }; type State = { valueNormal: boolean, valueCustom: boolean, }; class SwitchExample extends React.Component { static title = 'Switch'; state = { valueNormal: true, valueCustom: true, }; render() { const { theme: { colors: { background } } } = this.props; const switchValueNormalLabel = `switch ${ this.state.valueNormal === true ? 'on' : 'off' }`; const switchValueCustomlLabel = `switch ${ this.state.valueCustom === true ? 'on' : 'off' }`; return Platform.OS === 'android' ? ( this.setState(state => ({ valueNormal: !state.valueNormal, })) } > Normal {switchValueNormalLabel} this.setState(state => ({ valueCustom: !state.valueCustom, })) } > Custom {switchValueCustomlLabel} Switch on (disabled) Switch off (disabled) ) : ( Normal {switchValueNormalLabel} this.setState(state => ({ valueNormal: !state.valueNormal, })) } /> Custom {switchValueCustomlLabel} this.setState(state => ({ valueCustom: !state.valueCustom, })) } color={Colors.blue500} /> Switch on (disabled) Switch off (disabled) ); } } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: Colors.white, paddingVertical: 8, }, row: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingVertical: 8, paddingHorizontal: 16, }, }); export default withTheme(SwitchExample);