Massive/Switch.tsx

55 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-10-31 04:22:08 +00:00
import {useMemo} from 'react'
import {Pressable} from 'react-native'
import {Switch as PaperSwitch, Text} from 'react-native-paper'
import {CombinedDarkTheme, CombinedDefaultTheme} from './App'
import {useColor} from './color'
import {colorShade} from './colors'
import {MARGIN} from './constants'
import useDark from './use-dark'
2022-09-26 03:10:13 +00:00
export default function Switch({
value,
onValueChange,
onPress,
children,
}: {
2022-10-31 04:22:08 +00:00
value?: boolean
onValueChange: (value: boolean) => void
onPress: () => void
children: string
2022-09-26 03:10:13 +00:00
}) {
2022-10-31 04:22:08 +00:00
const {color} = useColor()
const dark = useDark()
const track = useMemo(() => {
if (dark)
return {
false: CombinedDarkTheme.colors.placeholder,
true: colorShade(color, -40),
2022-10-31 04:22:08 +00:00
}
return {
false: CombinedDefaultTheme.colors.placeholder,
true: colorShade(color, -40),
2022-10-31 04:22:08 +00:00
}
}, [dark, color])
2022-09-26 03:10:13 +00:00
return (
<Pressable
onPress={onPress}
style={{
flexDirection: 'row',
flexWrap: 'wrap',
alignItems: 'center',
}}>
<PaperSwitch
trackColor={track}
2022-09-26 03:10:13 +00:00
color={color}
style={{marginRight: MARGIN}}
value={value}
onValueChange={onValueChange}
/>
<Text>{children}</Text>
</Pressable>
2022-10-31 04:22:08 +00:00
)
2022-09-26 03:10:13 +00:00
}