2018-03-29 17:55:37 +00:00
|
|
|
import React from 'react';
|
2021-10-01 18:12:19 +00:00
|
|
|
import { Switch, Text, View } from 'react-native';
|
2018-03-29 17:55:37 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
import { SWITCH_TRACK_COLOR, themes } from '../../constants/colors';
|
2021-10-01 18:12:19 +00:00
|
|
|
import styles from './styles';
|
2018-03-29 17:55:37 +00:00
|
|
|
|
2021-10-01 18:12:19 +00:00
|
|
|
const SwitchContainer = React.memo(
|
|
|
|
({
|
|
|
|
children,
|
|
|
|
value,
|
|
|
|
disabled,
|
|
|
|
onValueChange,
|
|
|
|
leftLabelPrimary,
|
|
|
|
leftLabelSecondary,
|
|
|
|
rightLabelPrimary,
|
|
|
|
rightLabelSecondary,
|
|
|
|
theme,
|
|
|
|
testID,
|
|
|
|
labelContainerStyle,
|
|
|
|
leftLabelStyle
|
|
|
|
}) => (
|
|
|
|
<>
|
|
|
|
<View key='switch-container' style={[styles.switchContainer, children && styles.switchMargin]}>
|
|
|
|
{leftLabelPrimary && (
|
|
|
|
<View style={[styles.switchLabelContainer, labelContainerStyle]}>
|
|
|
|
<Text style={[styles.switchLabelPrimary, { color: themes[theme].titleText }, leftLabelStyle]}>
|
|
|
|
{leftLabelPrimary}
|
|
|
|
</Text>
|
|
|
|
<Text style={[styles.switchLabelSecondary, { color: themes[theme].titleText }, leftLabelStyle]}>
|
|
|
|
{leftLabelSecondary}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
)}
|
|
|
|
<Switch
|
|
|
|
style={styles.switch}
|
|
|
|
onValueChange={onValueChange}
|
|
|
|
value={value}
|
|
|
|
disabled={disabled}
|
|
|
|
trackColor={SWITCH_TRACK_COLOR}
|
|
|
|
testID={testID}
|
|
|
|
/>
|
|
|
|
{rightLabelPrimary && (
|
|
|
|
<View style={[styles.switchLabelContainer, labelContainerStyle]}>
|
|
|
|
<Text style={[styles.switchLabelPrimary, { color: themes[theme].titleText }, leftLabelStyle]}>
|
|
|
|
{rightLabelPrimary}
|
|
|
|
</Text>
|
|
|
|
<Text style={[styles.switchLabelSecondary, { color: themes[theme].titleText }, leftLabelStyle]}>
|
|
|
|
{rightLabelSecondary}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
)}
|
|
|
|
</View>
|
|
|
|
{children}
|
|
|
|
<View key='switch-divider' style={[styles.divider, { borderColor: themes[theme].separatorColor }]} />
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
);
|
2018-03-29 17:55:37 +00:00
|
|
|
|
2020-03-06 14:19:03 +00:00
|
|
|
SwitchContainer.propTypes = {
|
|
|
|
value: PropTypes.bool,
|
|
|
|
disabled: PropTypes.bool,
|
|
|
|
leftLabelPrimary: PropTypes.string,
|
|
|
|
leftLabelSecondary: PropTypes.string,
|
|
|
|
rightLabelPrimary: PropTypes.string,
|
|
|
|
rightLabelSecondary: PropTypes.string,
|
|
|
|
onValueChange: PropTypes.func,
|
|
|
|
theme: PropTypes.string,
|
|
|
|
testID: PropTypes.string,
|
|
|
|
labelContainerStyle: PropTypes.object,
|
|
|
|
leftLabelStyle: PropTypes.object,
|
|
|
|
children: PropTypes.any
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SwitchContainer;
|