Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

AppSymbol.tsx

237 lines10.8 KB

1import type { Icon } from "@tabler/icons-react-native/types";
2/*
3 * Keep these as per-icon exports. Importing the package root eagerly registers
4 * the entire Tabler icon set in Metro.
5 */
6import IconAdjustmentsHorizontal from "@tabler/icons-react-native/IconAdjustmentsHorizontal";
7import IconAlertCircle from "@tabler/icons-react-native/IconAlertCircle";
8import IconAlertTriangle from "@tabler/icons-react-native/IconAlertTriangle";
9import IconApps from "@tabler/icons-react-native/IconApps";
10import IconArchive from "@tabler/icons-react-native/IconArchive";
11import IconArrowBackUp from "@tabler/icons-react-native/IconArrowBackUp";
12import IconArrowDownCircle from "@tabler/icons-react-native/IconArrowDownCircle";
13import IconArrowRightCircle from "@tabler/icons-react-native/IconArrowRightCircle";
14import IconArrowUp from "@tabler/icons-react-native/IconArrowUp";
15import IconArrowUpCircle from "@tabler/icons-react-native/IconArrowUpCircle";
16import IconArrowUpRight from "@tabler/icons-react-native/IconArrowUpRight";
17import IconArrowUpRightCircle from "@tabler/icons-react-native/IconArrowUpRightCircle";
18import IconArrowsMaximize from "@tabler/icons-react-native/IconArrowsMaximize";
19import IconArrowsMinimize from "@tabler/icons-react-native/IconArrowsMinimize";
20import IconBellRinging from "@tabler/icons-react-native/IconBellRinging";
21import IconBolt from "@tabler/icons-react-native/IconBolt";
22import IconBox from "@tabler/icons-react-native/IconBox";
23import IconCamera from "@tabler/icons-react-native/IconCamera";
24import IconChartBar from "@tabler/icons-react-native/IconChartBar";
25import IconCheck from "@tabler/icons-react-native/IconCheck";
26import IconCloud from "@tabler/icons-react-native/IconCloud";
27import IconChevronDown from "@tabler/icons-react-native/IconChevronDown";
28import IconChevronLeft from "@tabler/icons-react-native/IconChevronLeft";
29import IconChevronRight from "@tabler/icons-react-native/IconChevronRight";
30import IconChevronUp from "@tabler/icons-react-native/IconChevronUp";
31import IconCircleCheck from "@tabler/icons-react-native/IconCircleCheck";
32import IconCircleXFilled from "@tabler/icons-react-native/IconCircleXFilled";
33import IconClock from "@tabler/icons-react-native/IconClock";
34import IconCode from "@tabler/icons-react-native/IconCode";
35import IconCopy from "@tabler/icons-react-native/IconCopy";
36import IconDeviceDesktop from "@tabler/icons-react-native/IconDeviceDesktop";
37import IconDeviceLaptop from "@tabler/icons-react-native/IconDeviceLaptop";
38import IconDots from "@tabler/icons-react-native/IconDots";
39import IconDotsCircleHorizontal from "@tabler/icons-react-native/IconDotsCircleHorizontal";
40import IconEdit from "@tabler/icons-react-native/IconEdit";
41import IconExternalLink from "@tabler/icons-react-native/IconExternalLink";
42import IconEye from "@tabler/icons-react-native/IconEye";
43import IconFileText from "@tabler/icons-react-native/IconFileText";
44import IconFilter from "@tabler/icons-react-native/IconFilter";
45import IconFilterFilled from "@tabler/icons-react-native/IconFilterFilled";
46import IconFolder from "@tabler/icons-react-native/IconFolder";
47import IconFolderOpen from "@tabler/icons-react-native/IconFolderOpen";
48import IconFolderPlus from "@tabler/icons-react-native/IconFolderPlus";
49import IconGitBranch from "@tabler/icons-react-native/IconGitBranch";
50import IconGitMerge from "@tabler/icons-react-native/IconGitMerge";
51import IconGitPullRequest from "@tabler/icons-react-native/IconGitPullRequest";
52import IconHammer from "@tabler/icons-react-native/IconHammer";
53import IconInfoCircle from "@tabler/icons-react-native/IconInfoCircle";
54import IconKeyboard from "@tabler/icons-react-native/IconKeyboard";
55import IconKeyboardHide from "@tabler/icons-react-native/IconKeyboardHide";
56import IconLayoutColumns from "@tabler/icons-react-native/IconLayoutColumns";
57import IconLayoutSidebar from "@tabler/icons-react-native/IconLayoutSidebar";
58import IconLayoutSidebarRight from "@tabler/icons-react-native/IconLayoutSidebarRight";
59import IconLetterSpacing from "@tabler/icons-react-native/IconLetterSpacing";
60import IconLink from "@tabler/icons-react-native/IconLink";
61import IconMessage from "@tabler/icons-react-native/IconMessage";
62import IconMinus from "@tabler/icons-react-native/IconMinus";
63import IconMoon from "@tabler/icons-react-native/IconMoon";
64import IconNetwork from "@tabler/icons-react-native/IconNetwork";
65import IconPalette from "@tabler/icons-react-native/IconPalette";
66import IconPhoto from "@tabler/icons-react-native/IconPhoto";
67import IconPin from "@tabler/icons-react-native/IconPin";
68import IconPinnedOff from "@tabler/icons-react-native/IconPinnedOff";
69import IconPlayerPlay from "@tabler/icons-react-native/IconPlayerPlay";
70import IconPlayerStopFilled from "@tabler/icons-react-native/IconPlayerStopFilled";
71import IconPlus from "@tabler/icons-react-native/IconPlus";
72import IconQrcode from "@tabler/icons-react-native/IconQrcode";
73import IconRefresh from "@tabler/icons-react-native/IconRefresh";
74import IconSearch from "@tabler/icons-react-native/IconSearch";
75import IconServer from "@tabler/icons-react-native/IconServer";
76import IconSettings from "@tabler/icons-react-native/IconSettings";
77import IconSparkles from "@tabler/icons-react-native/IconSparkles";
78import IconSun from "@tabler/icons-react-native/IconSun";
79import IconTerminal2 from "@tabler/icons-react-native/IconTerminal2";
80import IconTextDecrease from "@tabler/icons-react-native/IconTextDecrease";
81import IconTextIncrease from "@tabler/icons-react-native/IconTextIncrease";
82import IconTool from "@tabler/icons-react-native/IconTool";
83import IconTrash from "@tabler/icons-react-native/IconTrash";
84import IconTypography from "@tabler/icons-react-native/IconTypography";
85import IconUserCircle from "@tabler/icons-react-native/IconUserCircle";
86import IconWifiOff from "@tabler/icons-react-native/IconWifiOff";
87import IconWorld from "@tabler/icons-react-native/IconWorld";
88import IconX from "@tabler/icons-react-native/IconX";
89import type { SFSymbol, SymbolViewProps } from "expo-symbols";
90import { withUniwind } from "uniwind";
91​
92const ANDROID_ICON_BY_SF_SYMBOL: Partial<Record<SFSymbol, Icon>> = {
93 "arrow.branch": IconGitBranch,
94 "arrow.clockwise": IconRefresh,
95 "arrow.down.circle": IconArrowDownCircle,
96 "arrow.right.circle": IconArrowRightCircle,
97 "arrow.triangle.branch": IconGitBranch,
98 "arrow.triangle.pull": IconGitPullRequest,
99 "arrow.turn.left.up": IconArrowBackUp,
100 "arrow.up": IconArrowUp,
101 "arrow.up.circle": IconArrowUpCircle,
102 "arrow.up.left.and.arrow.down.right": IconArrowsMaximize,
103 "arrow.down.right.and.arrow.up.left": IconArrowsMinimize,
104 "arrow.up.right": IconArrowUpRight,
105 "arrow.up.right.circle": IconArrowUpRightCircle,
106 "arrow.uturn.backward": IconArrowBackUp,
107 archivebox: IconArchive,
108 "archivebox.fill": IconArchive,
109 "bell.badge": IconBellRinging,
110 "bolt.circle": IconBolt,
111 "bolt.horizontal.circle": IconBolt,
112 camera: IconCamera,
113 "chart.bar.xaxis": IconChartBar,
114 checkmark: IconCheck,
115 "checkmark.circle": IconCircleCheck,
116 clock: IconClock,
117 cloud: IconCloud,
118 cube: IconBox,
119 "chevron.down": IconChevronDown,
120 "chevron.left": IconChevronLeft,
121 "chevron.left.forwardslash.chevron.right": IconCode,
122 "chevron.right": IconChevronRight,
123 "chevron.up": IconChevronUp,
124 desktopcomputer: IconDeviceDesktop,
125 "doc.on.doc": IconCopy,
126 "doc.text": IconFileText,
127 ellipsis: IconDots,
128 moon: IconMoon,
129 "ellipsis.circle": IconDotsCircleHorizontal,
130 "exclamationmark.triangle": IconAlertTriangle,
131 eye: IconEye,
132 folder: IconFolder,
133 "folder.badge.plus": IconFolderPlus,
134 "folder.fill": IconFolder,
135 gearshape: IconSettings,
136 "info.circle": IconInfoCircle,
137 laptopcomputer: IconDeviceLaptop,
138 link: IconLink,
139 "line.3.horizontal.decrease.circle": IconFilter,
140 "line.3.horizontal.decrease.circle.fill": IconFilterFilled,
141 // Tabler has no Apple desktops; the closest silhouettes stand in on Android.
142 macmini: IconServer,
143 macstudio: IconDeviceDesktop,
144 magnifyingglass: IconSearch,
145 paintbrush: IconPalette,
146 "person.crop.circle": IconUserCircle,
147 photo: IconPhoto,
148 pin: IconPin,
149 "pin.slash": IconPinnedOff,
150 play: IconPlayerPlay,
151 plus: IconPlus,
152 "qrcode.viewfinder": IconQrcode,
153 "point.3.connected.trianglepath.dotted": IconNetwork,
154 "point.topleft.down.curvedto.point.bottomright.up": IconGitMerge,
155 safari: IconExternalLink,
156 "server.rack": IconServer,
157 "sidebar.left": IconLayoutSidebar,
158 "sidebar.right": IconLayoutSidebarRight,
159 "slider.horizontal.3": IconAdjustmentsHorizontal,
160 "square.and.pencil": IconEdit,
161 "square.grid.2x2": IconApps,
162 "square.split.2x1": IconLayoutColumns,
163 "sun.max": IconSun,
164 "stop.fill": IconPlayerStopFilled,
165 terminal: IconTerminal2,
166 "text.bubble": IconMessage,
167 "text.word.spacing": IconLetterSpacing,
168 "textformat.size": IconTypography,
169 "textformat.size.larger": IconTextIncrease,
170 "textformat.size.smaller": IconTextDecrease,
171 trash: IconTrash,
172 "wifi.slash": IconWifiOff,
173 xmark: IconX,
174 "xmark.circle.fill": IconCircleXFilled,
175};
176​
177// Callers can pass `{ ios, android }` names where `android` is a Material
178// icon name (the raw expo-symbols contract). Resolve those here too so the
179// android key keeps working through this wrapper — it wins over the SF map
180// when both match (e.g. folder vs folder_open for expanded project groups).
181const ANDROID_ICON_BY_MATERIAL_NAME: Record<string, Icon> = {
182 auto_awesome: IconSparkles,
183 bolt: IconBolt,
184 build: IconTool,
185 chat_bubble: IconMessage,
186 check: IconCheck,
187 close: IconX,
188 construction: IconHammer,
189 content_copy: IconCopy,
190 desktop_windows: IconDeviceDesktop,
191 edit: IconEdit,
192 error: IconAlertCircle,
193 folder: IconFolder,
194 folder_open: IconFolderOpen,
195 keyboard: IconKeyboard,
196 keyboard_arrow_down: IconChevronDown,
197 keyboard_arrow_up: IconChevronUp,
198 keyboard_hide: IconKeyboardHide,
199 public: IconWorld,
200 remove: IconMinus,
201 terminal: IconTerminal2,
202 visibility: IconEye,
203};
204​
205export type { SFSymbol } from "expo-symbols";
206export type AppSymbolName = SymbolViewProps["name"];
207​
208function AppSymbolView(props: SymbolViewProps) {
209 const materialName = typeof props.name === "string" ? undefined : props.name.android;
210 const sfSymbol = typeof props.name === "string" ? props.name : props.name.ios;
211 const AndroidIcon =
212 (materialName ? ANDROID_ICON_BY_MATERIAL_NAME[materialName] : undefined) ??
213 (sfSymbol ? ANDROID_ICON_BY_SF_SYMBOL[sfSymbol] : undefined);
214​
215 if (!AndroidIcon) {
216 return props.fallback ?? null;
217 }
218​
219 return (
220 <AndroidIcon
221 accessibilityLabel={props.accessibilityLabel}
222 color={props.tintColor}
223 size={props.size}
224 strokeWidth={2}
225 style={props.style}
226 testID={props.testID}
227 />
228 );
230​
231/**
232 * expo-symbols and the Android Tabler fallback both expose tint as a native
233 * prop rather than a React Native style. Keep that third-party boundary here
234 * so callers can use Uniwind's `tintColorClassName` instead of subscribing to
235 * theme variables in every parent component.
236 */
237export const SymbolView = withUniwind(AppSymbolView);