Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(mobile): tapping an Android switch no longer presses its row #15121

Closedatharvadeosthale(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/15121/headopened View on GitHub

Showing 1 changed file with 9 additions and 1 deletion.

x
0 of 1 viewed, 1 left
9 additions and 1 deletionapps/mobile/src/components/MaterialSwitch.android.tsxModified
View file
@@ -1,9 +1,16 @@
import { Host, Switch as ComposeSwitch } from "@expo/ui/jetpack-compose";
-import { View } from "react-native";
+import { View, type ViewProps } from "react-native";
import type { ThemedSwitchProps } from "./MaterialSwitch.types";
​
import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider";
​
+// Like RN's Switch, own the touch so a pressable row around the switch never takes it. Claimed on
+// the Compose Host because a React Native View holding the touch would cancel the native switch.
+const ownTouch: Pick<ViewProps, "onStartShouldSetResponder" | "onResponderTerminationRequest"> = {
+ onStartShouldSetResponder: () => true,
+ onResponderTerminationRequest: () => false,
+};
+​
/** Material's native switch, with the same palette and accessibility contract as our RN controls. */
export function MaterialSwitch(props: ThemedSwitchProps) {
const { themeAppearance, themeVariables: colors } = useAppearancePreferences();
@@ -25,6 +32,7 @@
<View importantForAccessibility="no-hide-descendants">
<Host
+ {...ownTouch}
colorScheme={themeAppearance}
ignoreSafeAreaKeyboardInsets
style={{ width: 52, height: 48 }}