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