2018-03-29 17:55:37 +00:00
|
|
|
import React from 'react';
|
2022-02-25 21:24:08 +00:00
|
|
|
import { Switch, Text, TextStyle, View, ViewStyle } from 'react-native';
|
2018-03-29 17:55:37 +00:00
|
|
|
|
2022-04-12 16:27:05 +00:00
|
|
|
import { TSupportedThemes } from '../../theme';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { SWITCH_TRACK_COLOR, themes } from '../../lib/constants';
|
2021-09-13 20:41:05 +00:00
|
|
|
import styles from './styles';
|
2018-03-29 17:55:37 +00:00
|
|
|
|
2022-02-25 21:24:08 +00:00
|
|
|
interface ISwitchContainer {
|
|
|
|
value: boolean;
|
|
|
|
disabled?: boolean;
|
|
|
|
leftLabelPrimary: string;
|
|
|
|
leftLabelSecondary: string;
|
|
|
|
rightLabelPrimary?: string;
|
|
|
|
rightLabelSecondary?: string;
|
|
|
|
onValueChange: (value: any) => void;
|
2022-04-12 16:27:05 +00:00
|
|
|
theme: TSupportedThemes;
|
2022-02-25 21:24:08 +00:00
|
|
|
testID: string;
|
|
|
|
labelContainerStyle?: ViewStyle;
|
|
|
|
leftLabelStyle?: TextStyle;
|
|
|
|
}
|
|
|
|
|
2023-08-18 17:48:33 +00:00
|
|
|
const SwitchContainer: React.FC<ISwitchContainer> = React.memo(
|
2021-09-13 20:41:05 +00:00
|
|
|
({
|
|
|
|
children,
|
|
|
|
value,
|
|
|
|
disabled,
|
|
|
|
onValueChange,
|
|
|
|
leftLabelPrimary,
|
|
|
|
leftLabelSecondary,
|
|
|
|
rightLabelPrimary,
|
|
|
|
rightLabelSecondary,
|
|
|
|
theme,
|
|
|
|
testID,
|
|
|
|
labelContainerStyle,
|
|
|
|
leftLabelStyle
|
2023-08-18 17:48:33 +00:00
|
|
|
}) => (
|
2021-09-13 20:41:05 +00:00
|
|
|
<>
|
2022-02-25 21:24:08 +00:00
|
|
|
<View key='switch-container' style={[styles.switchContainer, !!children && styles.switchMargin]}>
|
2021-09-13 20:41:05 +00:00
|
|
|
{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
|
|
|
export default SwitchContainer;
|