Simplify Switch.tsx
This commit is contained in:
parent
27b7e91e91
commit
48432188c3
|
@ -79,8 +79,7 @@ export default function EditPlan() {
|
|||
{DAYS.map(day => (
|
||||
<Switch
|
||||
key={day}
|
||||
onValueChange={value => toggleDay(value, day)}
|
||||
onPress={() => toggleDay(!days.includes(day), day)}
|
||||
onChange={value => toggleDay(value, day)}
|
||||
value={days.includes(day)}>
|
||||
{day}
|
||||
</Switch>
|
||||
|
@ -94,9 +93,8 @@ export default function EditPlan() {
|
|||
names.map(name => (
|
||||
<Switch
|
||||
key={name}
|
||||
onValueChange={value => toggleWorkout(value, name)}
|
||||
value={workouts.includes(name)}
|
||||
onPress={() => toggleWorkout(!workouts.includes(name), name)}>
|
||||
onChange={value => toggleWorkout(value, name)}
|
||||
value={workouts.includes(name)}>
|
||||
{name}
|
||||
</Switch>
|
||||
))
|
||||
|
|
|
@ -192,11 +192,7 @@ export default function SettingsPage() {
|
|||
|
||||
const renderSwitch = useCallback(
|
||||
(item: Input<boolean>) => (
|
||||
<Switch
|
||||
onPress={() => item.onChange(!item.value)}
|
||||
key={item.name}
|
||||
value={item.value}
|
||||
onValueChange={item.onChange}>
|
||||
<Switch key={item.name} value={item.value} onChange={item.onChange}>
|
||||
{item.name}
|
||||
</Switch>
|
||||
),
|
||||
|
|
10
Switch.tsx
10
Switch.tsx
|
@ -4,20 +4,18 @@ import {MARGIN} from './constants'
|
|||
|
||||
export default function Switch({
|
||||
value,
|
||||
onValueChange,
|
||||
onPress,
|
||||
onChange,
|
||||
children,
|
||||
}: {
|
||||
value?: boolean
|
||||
onValueChange: (value: boolean) => void
|
||||
onPress: () => void
|
||||
onChange: (value: boolean) => void
|
||||
children: string
|
||||
}) {
|
||||
const {colors} = useTheme()
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
onPress={onPress}
|
||||
onPress={() => onChange(!value)}
|
||||
style={{
|
||||
flexDirection: 'row',
|
||||
flexWrap: 'wrap',
|
||||
|
@ -28,7 +26,7 @@ export default function Switch({
|
|||
color={colors.primary}
|
||||
style={{marginRight: MARGIN}}
|
||||
value={value}
|
||||
onValueChange={onValueChange}
|
||||
onValueChange={onChange}
|
||||
/>
|
||||
<Text>{children}</Text>
|
||||
</Pressable>
|
||||
|
|
Loading…
Reference in New Issue
Block a user