Skip to content

Commit a9f0fd4

Browse files
t3dotggclaude
andcommitted
fix(mobile): Android environment toggles toggle instead of opening the row
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 16918b5 commit a9f0fd4

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
import { NativeThemeHost } from "./NativeThemeHost.android";
22
import { Switch as ComposeSwitch } from "@expo/ui/jetpack-compose";
3-
import { View } from "react-native";
3+
import { Pressable, View } from "react-native";
44
import type { ThemedSwitchProps } from "./NativeSwitch.types";
55

66
import { useControlTheme } from "./useControlTheme";
77

8-
/** Material's native switch, with the same palette and accessibility contract as our RN controls. */
8+
/**
9+
* Material's native switch, with the same palette and accessibility contract as our RN controls.
10+
* Compose only draws it. The RN Pressable owns the touch so it wins over a pressable parent row;
11+
* with Compose handling touches, a tap on the switch ran the row's onPress instead.
12+
*/
913
export function NativeSwitch(props: ThemedSwitchProps) {
1014
const { colors } = useControlTheme();
11-
const toggle = () => {
12-
if (!props.disabled) props.onValueChange?.(!props.value);
13-
};
1415

1516
return (
16-
<View
17-
accessible
17+
<Pressable
18+
disabled={props.disabled}
19+
onPress={() => props.onValueChange?.(!props.value)}
1820
accessibilityLabel={props.accessibilityLabel}
1921
accessibilityHint={props.accessibilityHint}
2022
accessibilityRole="switch"
2123
accessibilityState={{ checked: Boolean(props.value), disabled: Boolean(props.disabled) }}
22-
accessibilityActions={[{ name: "activate", label: "Toggle" }]}
23-
onAccessibilityAction={toggle}
2424
style={props.style}
2525
testID={props.testID}
2626
>
27-
<View importantForAccessibility="no-hide-descendants">
27+
<View importantForAccessibility="no-hide-descendants" pointerEvents="none">
2828
<NativeThemeHost ignoreSafeAreaKeyboardInsets style={{ width: 52, height: 48 }}>
2929
<ComposeSwitch
3030
value={Boolean(props.value)}
3131
enabled={!props.disabled}
32-
onCheckedChange={props.onValueChange ?? undefined}
3332
colors={{
3433
checkedTrackColor: colors["--color-switch-active-track"],
3534
checkedThumbColor: colors["--color-switch-active-thumb"],
@@ -41,6 +40,6 @@ export function NativeSwitch(props: ThemedSwitchProps) {
4140
/>
4241
</NativeThemeHost>
4342
</View>
44-
</View>
43+
</Pressable>
4544
);
4645
}

0 commit comments

Comments
 (0)