Open History to see the last commit
1import {
2 FilledIconButton,
3 FilledTonalIconButton,
4 Host,
5 IconButton,
6} from "@expo/ui/jetpack-compose";
7import { size } from "@expo/ui/jetpack-compose/modifiers";
8import { View } from "react-native";
9
10import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider";
11import { SymbolView, type AppSymbolName } from "./AppSymbol";
12
13export function MaterialIconButton(props: {
14 readonly accessibilityLabel: string;
15 readonly icon: AppSymbolName;
16 readonly onPress?: () => void;
17 readonly disabled?: boolean;
18 readonly selected?: boolean;
19 readonly variant?: "standard" | "primary" | "tonal" | "danger";
20 readonly tintColorClassName?: string;
21}) {
22 const { themeAppearance, themeVariables: colors } = useAppearancePreferences();
23 const variant = props.variant ?? "standard";
24 const Component =
25 variant === "standard"
26 ? IconButton
27 : variant === "tonal"
28 ? FilledTonalIconButton
29 : FilledIconButton;
30 const containerColor =
31 variant === "primary"
32 ? colors["--color-primary"]
33 : variant === "danger"
34 ? colors["--color-danger"]
35 : colors["--color-secondary"];
36 const iconTint = props.disabled
37 ? "accent-icon-subtle"
38 : variant === "primary"
39 ? "accent-primary-foreground"
40 : variant === "danger"
41 ? "accent-danger-foreground"
42 : variant === "tonal"
43 ? "accent-secondary-foreground"
44 : (props.tintColorClassName ?? "accent-foreground");
45 return (
46 <View
47 accessible
48 accessibilityLabel={props.accessibilityLabel}
49 accessibilityRole="button"
50 accessibilityState={{ disabled: Boolean(props.disabled), selected: props.selected }}
51 accessibilityActions={[{ name: "activate" }]}
52 onAccessibilityAction={() => {
53 if (!props.disabled) props.onPress?.();
54 }}
55 style={{ width: 48, height: 48 }}
56 >
57 <View importantForAccessibility="no-hide-descendants">
58 <Host
59 colorScheme={themeAppearance}
60 ignoreSafeAreaKeyboardInsets
61 style={{ width: 48, height: 48 }}
62 >
63 <Component
64 onClick={props.onPress}
65 enabled={!props.disabled}
66 modifiers={[size(48, 48)]}
67 colors={
68 variant === "standard"
69 ? undefined
70 : { containerColor, disabledContainerColor: colors["--color-subtle-strong"] }
71 }
72 >
73 {null}
74 </Component>
75 </Host>
76 </View>
77 {/* Keep RN SVG measurement outside Compose; the native button owns touch and ripple. */}
78 <View pointerEvents="none" className="absolute inset-0 items-center justify-center">
79 <SymbolView
80 name={props.icon === "ellipsis" ? { ios: "ellipsis", android: "more_vert" } : props.icon}
81 size={24}
82 tintColorClassName={iconTint}
83 type="monochrome"
84 />
85 </View>
86 </View>
87 );
88}