11import { NativeThemeHost } from "./NativeThemeHost.android" ;
22import { Switch as ComposeSwitch } from "@expo/ui/jetpack-compose" ;
3- import { View } from "react-native" ;
3+ import { Pressable , View } from "react-native" ;
44import type { ThemedSwitchProps } from "./NativeSwitch.types" ;
55
66import { 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+ */
913export 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