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}) {
21 const { themeAppearance, themeVariables: colors } = useAppearancePreferences();
22 const variant = props.variant ?? "standard";
23 const Component =
24 variant === "standard"
25 ? IconButton
26 : variant === "tonal"
27 ? FilledTonalIconButton
28 : FilledIconButton;
29 const containerColor =
30 variant === "primary"
31 ? colors["--color-primary"]
32 : variant === "danger"
33 ? colors["--color-danger"]
34 : colors["--color-secondary"];
35 const iconTint = props.disabled
36 ? "accent-icon-subtle"
37 : variant === "primary"
38 ? "accent-primary-foreground"
39 : variant === "danger"
40 ? "accent-danger-foreground"
41 : variant === "tonal"
42 ? "accent-secondary-foreground"
43 : "accent-foreground";
44 return (
45 <View
46 accessible
47 accessibilityLabel={props.accessibilityLabel}
48 accessibilityRole="button"
49 accessibilityState={{ disabled: Boolean(props.disabled), selected: props.selected }}
50 accessibilityActions={[{ name: "activate" }]}
51 onAccessibilityAction={() => {
52 if (!props.disabled) props.onPress?.();
53 }}
54 style={{ width: 48, height: 48 }}
55 >
56 <View importantForAccessibility="no-hide-descendants">
57 <Host
58 colorScheme={themeAppearance}
59 ignoreSafeAreaKeyboardInsets
60 style={{ width: 48, height: 48 }}
61 >
62 <Component
63 onClick={props.onPress}
64 enabled={!props.disabled}
65 modifiers={[size(48, 48)]}
66 colors={
67 variant === "standard"
68 ? undefined
69 : { containerColor, disabledContainerColor: colors["--color-subtle-strong"] }
70 }
71 >
72 {null}
73 </Component>
74 </Host>
75 </View>
76 {/* Keep RN SVG measurement outside Compose; the native button owns touch and ripple. */}
77 <View pointerEvents="none" className="absolute inset-0 items-center justify-center">
78 <SymbolView
79 name={props.icon === "ellipsis" ? { ios: "ellipsis", android: "more_vert" } : props.icon}
80 size={24}
81 tintColorClassName={iconTint}
82 type="monochrome"
83 />
84 </View>
85 </View>
86 );
87}