Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion apps/mobile/src/components/MaterialSwitch.android.tsx
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -25,6 +32,7 @@ export function MaterialSwitch(props: ThemedSwitchProps) {
>
<View importantForAccessibility="no-hide-descendants">
<Host
{...ownTouch}
colorScheme={themeAppearance}
ignoreSafeAreaKeyboardInsets
style={{ width: 52, height: 48 }}
Expand Down
Loading