2018-03-29 17:55:37 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { View, Text, Switch } from 'react-native';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
import styles from './styles';
|
2018-09-25 19:28:42 +00:00
|
|
|
import sharedStyles from '../Styles';
|
2019-06-28 17:02:30 +00:00
|
|
|
import { SWITCH_TRACK_COLOR } from '../../constants/colors';
|
2018-03-29 17:55:37 +00:00
|
|
|
|
|
|
|
export default class SwitchContainer extends React.PureComponent {
|
|
|
|
static propTypes = {
|
|
|
|
value: PropTypes.bool,
|
|
|
|
disabled: PropTypes.bool,
|
|
|
|
leftLabelPrimary: PropTypes.string,
|
|
|
|
leftLabelSecondary: PropTypes.string,
|
|
|
|
rightLabelPrimary: PropTypes.string,
|
|
|
|
rightLabelSecondary: PropTypes.string,
|
2018-05-23 13:39:18 +00:00
|
|
|
onValueChange: PropTypes.func,
|
|
|
|
testID: PropTypes.string
|
2018-03-29 17:55:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
2018-05-23 13:39:18 +00:00
|
|
|
value, disabled, onValueChange, leftLabelPrimary, leftLabelSecondary, rightLabelPrimary, rightLabelSecondary, testID
|
2018-03-29 17:55:37 +00:00
|
|
|
} = this.props;
|
|
|
|
return (
|
|
|
|
[
|
|
|
|
<View key='switch-container' style={styles.switchContainer}>
|
|
|
|
<View style={[styles.switchLabelContainer, sharedStyles.alignItemsFlexEnd]}>
|
|
|
|
<Text style={styles.switchLabelPrimary}>{leftLabelPrimary}</Text>
|
|
|
|
<Text style={[styles.switchLabelSecondary, sharedStyles.textAlignRight]}>{leftLabelSecondary}</Text>
|
|
|
|
</View>
|
|
|
|
<Switch
|
|
|
|
style={styles.switch}
|
|
|
|
onValueChange={onValueChange}
|
|
|
|
value={value}
|
|
|
|
disabled={disabled}
|
2019-06-28 17:02:30 +00:00
|
|
|
trackColor={SWITCH_TRACK_COLOR}
|
2018-05-23 13:39:18 +00:00
|
|
|
testID={testID}
|
2018-03-29 17:55:37 +00:00
|
|
|
/>
|
|
|
|
<View style={styles.switchLabelContainer}>
|
|
|
|
<Text style={styles.switchLabelPrimary}>{rightLabelPrimary}</Text>
|
|
|
|
<Text style={styles.switchLabelSecondary}>{rightLabelSecondary}</Text>
|
|
|
|
</View>
|
|
|
|
</View>,
|
|
|
|
<View key='switch-divider' style={styles.divider} />
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|