Massive/Switch.tsx

42 lines
1006 B
TypeScript
Raw Normal View History

2022-12-24 06:49:43 +00:00
import {Control, Controller} from 'react-hook-form'
import {Platform, Pressable} from 'react-native'
import {Switch as PaperSwitch, Text, useTheme} from 'react-native-paper'
2022-10-31 04:22:08 +00:00
import {MARGIN} from './constants'
2022-09-26 03:10:13 +00:00
export default function Switch({
2022-12-24 06:49:43 +00:00
control,
name,
2022-09-26 03:10:13 +00:00
children,
}: {
2022-12-24 06:49:43 +00:00
name: string
control: Control<any, any>
2022-10-31 04:22:08 +00:00
children: string
2022-09-26 03:10:13 +00:00
}) {
const {colors} = useTheme()
2022-09-26 03:10:13 +00:00
return (
2022-12-24 06:49:43 +00:00
<Controller
name={name}
control={control}
render={({field: {onChange, value}}) => (
<Pressable
onPress={() => onChange(!value)}
style={{
flexDirection: 'row',
flexWrap: 'wrap',
alignItems: 'center',
marginBottom: Platform.OS === 'ios' ? MARGIN : null,
}}>
<PaperSwitch
color={colors.primary}
style={{marginRight: MARGIN}}
value={value}
onValueChange={onChange}
/>
<Text>{children}</Text>
</Pressable>
)}
/>
2022-10-31 04:22:08 +00:00
)
2022-09-26 03:10:13 +00:00
}