Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(mobile): Android environment toggles toggle instead of opening the row #21041

Closedt3dotgg(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromfix/android-env-switch-toggleopened View on GitHub

Showing 1 changed file with 11 additions and 12 deletions.

x
0 of 1 viewed, 1 left
11 additions and 12 deletionsapps/mobile/src/components/ui/NativeSwitch.android.tsxModified
View file
@@ -1,35 +1,34 @@
import { NativeThemeHost } from "./NativeThemeHost.android";
import { Switch as ComposeSwitch } from "@expo/ui/jetpack-compose";
-import { View } from "react-native";
+import { Pressable, View } from "react-native";
import type { ThemedSwitchProps } from "./NativeSwitch.types";
​
import { useControlTheme } from "./useControlTheme";
​
-/** Material's native switch, with the same palette and accessibility contract as our RN controls. */
+/**
+ * Material's native switch, with the same palette and accessibility contract as our RN controls.
+ * Compose only draws it. The RN Pressable owns the touch so it wins over a pressable parent row;
+ * with Compose handling touches, a tap on the switch ran the row's onPress instead.
+ */
export function NativeSwitch(props: ThemedSwitchProps) {
const { colors } = useControlTheme();
- const toggle = () => {
- if (!props.disabled) props.onValueChange?.(!props.value);
- };
​
return (
- <View
- accessible
+ <Pressable
+ disabled={props.disabled}
+ onPress={() => props.onValueChange?.(!props.value)}
accessibilityLabel={props.accessibilityLabel}
accessibilityHint={props.accessibilityHint}
accessibilityRole="switch"
accessibilityState={{ checked: Boolean(props.value), disabled: Boolean(props.disabled) }}