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

AppSymbol.tsx

365 lines16.4 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 IconAlignLeft from "@tabler/icons-react-native/IconAlignLeft";
8import IconAlertCircle from "@tabler/icons-react-native/IconAlertCircle";
9import IconAlertTriangle from "@tabler/icons-react-native/IconAlertTriangle";
10import IconApps from "@tabler/icons-react-native/IconApps";
11import IconArchive from "@tabler/icons-react-native/IconArchive";
12import IconArrowBackUp from "@tabler/icons-react-native/IconArrowBackUp";
13import IconArrowDown from "@tabler/icons-react-native/IconArrowDown";
14import IconArrowForwardUp from "@tabler/icons-react-native/IconArrowForwardUp";
15import IconArrowLeft from "@tabler/icons-react-native/IconArrowLeft";
16import IconArrowRight from "@tabler/icons-react-native/IconArrowRight";
17import IconArrowDownCircle from "@tabler/icons-react-native/IconArrowDownCircle";
18import IconArrowRightCircle from "@tabler/icons-react-native/IconArrowRightCircle";
19import IconArrowUp from "@tabler/icons-react-native/IconArrowUp";
20import IconArrowUpCircle from "@tabler/icons-react-native/IconArrowUpCircle";
21import IconArrowUpRight from "@tabler/icons-react-native/IconArrowUpRight";
22import IconArrowUpRightCircle from "@tabler/icons-react-native/IconArrowUpRightCircle";
23import IconArrowsLeftRight from "@tabler/icons-react-native/IconArrowsLeftRight";
24import IconArrowsDiagonal2 from "@tabler/icons-react-native/IconArrowsDiagonal2";
25import IconArrowsMinimize from "@tabler/icons-react-native/IconArrowsMinimize";
26import IconBellRinging from "@tabler/icons-react-native/IconBellRinging";
27import IconBolt from "@tabler/icons-react-native/IconBolt";
28import IconBox from "@tabler/icons-react-native/IconBox";
29import IconBrain from "@tabler/icons-react-native/IconBrain";
30import IconCamera from "@tabler/icons-react-native/IconCamera";
31import IconCar from "@tabler/icons-react-native/IconCar";
32import IconChartBar from "@tabler/icons-react-native/IconChartBar";
33import IconCheck from "@tabler/icons-react-native/IconCheck";
34import IconCloud from "@tabler/icons-react-native/IconCloud";
35import IconChevronDown from "@tabler/icons-react-native/IconChevronDown";
36import IconChevronLeft from "@tabler/icons-react-native/IconChevronLeft";
37import IconChevronRight from "@tabler/icons-react-native/IconChevronRight";
38import IconChevronUp from "@tabler/icons-react-native/IconChevronUp";
39import IconCircle from "@tabler/icons-react-native/IconCircle";
40import IconCircleCheck from "@tabler/icons-react-native/IconCircleCheck";
41import IconCircleDashed from "@tabler/icons-react-native/IconCircleDashed";
42import IconCircleDot from "@tabler/icons-react-native/IconCircleDot";
43import IconCircleXFilled from "@tabler/icons-react-native/IconCircleXFilled";
44import IconTicket from "@tabler/icons-react-native/IconTicket";
45import IconClock from "@tabler/icons-react-native/IconClock";
46import IconCode from "@tabler/icons-react-native/IconCode";
47import IconCopy from "@tabler/icons-react-native/IconCopy";
48import IconDatabase from "@tabler/icons-react-native/IconDatabase";
49import IconDeviceDesktop from "@tabler/icons-react-native/IconDeviceDesktop";
50import IconDeviceLaptop from "@tabler/icons-react-native/IconDeviceLaptop";
51import IconDeviceMobile from "@tabler/icons-react-native/IconDeviceMobile";
52import IconDots from "@tabler/icons-react-native/IconDots";
53import IconPlusMinus from "@tabler/icons-react-native/IconPlusMinus";
54import IconDotsVertical from "@tabler/icons-react-native/IconDotsVertical";
55import IconDotsCircleHorizontal from "@tabler/icons-react-native/IconDotsCircleHorizontal";
56import IconEdit from "@tabler/icons-react-native/IconEdit";
57import IconExternalLink from "@tabler/icons-react-native/IconExternalLink";
58import IconEyeOff from "@tabler/icons-react-native/IconEyeOff";
59import IconEye from "@tabler/icons-react-native/IconEye";
60import IconFileText from "@tabler/icons-react-native/IconFileText";
61import IconFileDiff from "@tabler/icons-react-native/IconFileDiff";
62import IconFilter from "@tabler/icons-react-native/IconFilter";
63import IconFilterFilled from "@tabler/icons-react-native/IconFilterFilled";
64import IconFolder from "@tabler/icons-react-native/IconFolder";
65import IconFolderOpen from "@tabler/icons-react-native/IconFolderOpen";
66import IconHeadphones from "@tabler/icons-react-native/IconHeadphones";
67import IconFolderPlus from "@tabler/icons-react-native/IconFolderPlus";
68import IconGitPullRequestClosed from "@tabler/icons-react-native/IconGitPullRequestClosed";
69import IconGitPullRequestDraft from "@tabler/icons-react-native/IconGitPullRequestDraft";
70import IconGitCommit from "@tabler/icons-react-native/IconGitCommit";
71import IconGitBranch from "@tabler/icons-react-native/IconGitBranch";
72import IconGitMerge from "@tabler/icons-react-native/IconGitMerge";
73import IconGitPullRequest from "@tabler/icons-react-native/IconGitPullRequest";
74import IconHammer from "@tabler/icons-react-native/IconHammer";
75import IconHome from "@tabler/icons-react-native/IconHome";
76import IconInfoCircle from "@tabler/icons-react-native/IconInfoCircle";
77import IconKeyboard from "@tabler/icons-react-native/IconKeyboard";
78import IconKeyboardHide from "@tabler/icons-react-native/IconKeyboardHide";
79import IconLock from "@tabler/icons-react-native/IconLock";
80import IconLayoutColumns from "@tabler/icons-react-native/IconLayoutColumns";
81import IconLayoutSidebar from "@tabler/icons-react-native/IconLayoutSidebar";
82import IconLayoutSidebarRight from "@tabler/icons-react-native/IconLayoutSidebarRight";
83import IconLetterSpacing from "@tabler/icons-react-native/IconLetterSpacing";
84import IconMicrophone from "@tabler/icons-react-native/IconMicrophone";
85import IconLink from "@tabler/icons-react-native/IconLink";
86import IconListNumbers from "@tabler/icons-react-native/IconListNumbers";
87import IconMenu2 from "@tabler/icons-react-native/IconMenu2";
88import IconMessageCircleQuestion from "@tabler/icons-react-native/IconMessageCircleQuestion";
89import IconMessage from "@tabler/icons-react-native/IconMessage";
90import IconMessagePlus from "@tabler/icons-react-native/IconMessagePlus";
91import IconMinus from "@tabler/icons-react-native/IconMinus";
92import IconMoon from "@tabler/icons-react-native/IconMoon";
93import IconNetwork from "@tabler/icons-react-native/IconNetwork";
94import IconPalette from "@tabler/icons-react-native/IconPalette";
95import IconPencil from "@tabler/icons-react-native/IconPencil";
96import IconPlug from "@tabler/icons-react-native/IconPlug";
97import IconPhoto from "@tabler/icons-react-native/IconPhoto";
98import IconPin from "@tabler/icons-react-native/IconPin";
99import IconPinnedOff from "@tabler/icons-react-native/IconPinnedOff";
100import IconPlayerPlay from "@tabler/icons-react-native/IconPlayerPlay";
101import IconPlayerStopFilled from "@tabler/icons-react-native/IconPlayerStopFilled";
102import IconPlus from "@tabler/icons-react-native/IconPlus";
103import IconQrcode from "@tabler/icons-react-native/IconQrcode";
104import IconRefresh from "@tabler/icons-react-native/IconRefresh";
105import IconSearch from "@tabler/icons-react-native/IconSearch";
106import IconServer from "@tabler/icons-react-native/IconServer";
107import IconSettings from "@tabler/icons-react-native/IconSettings";
108import IconSparkles from "@tabler/icons-react-native/IconSparkles";
109import IconStack2 from "@tabler/icons-react-native/IconStack2";
110import IconStar from "@tabler/icons-react-native/IconStar";
111import IconStarFilled from "@tabler/icons-react-native/IconStarFilled";
112import IconStethoscope from "@tabler/icons-react-native/IconStethoscope";
113import IconSun from "@tabler/icons-react-native/IconSun";
114import IconShieldQuestion from "@tabler/icons-react-native/IconShieldQuestion";
115import IconTarget from "@tabler/icons-react-native/IconTarget";
116import IconTerminal2 from "@tabler/icons-react-native/IconTerminal2";
117import IconTextDecrease from "@tabler/icons-react-native/IconTextDecrease";
118import IconTextIncrease from "@tabler/icons-react-native/IconTextIncrease";
119import IconTool from "@tabler/icons-react-native/IconTool";
120import IconTrash from "@tabler/icons-react-native/IconTrash";
121import IconTypography from "@tabler/icons-react-native/IconTypography";
122import IconUpload from "@tabler/icons-react-native/IconUpload";
123import IconUserCircle from "@tabler/icons-react-native/IconUserCircle";
124import IconUserCheck from "@tabler/icons-react-native/IconUserCheck";
125import IconUserX from "@tabler/icons-react-native/IconUserX";
126import IconUserQuestion from "@tabler/icons-react-native/IconUserQuestion";
127import IconUserPlus from "@tabler/icons-react-native/IconUserPlus";
128import IconUsers from "@tabler/icons-react-native/IconUsers";
129import IconWifi from "@tabler/icons-react-native/IconWifi";
130import IconWifiOff from "@tabler/icons-react-native/IconWifiOff";
131import IconWorld from "@tabler/icons-react-native/IconWorld";
132import IconX from "@tabler/icons-react-native/IconX";
133import type { AndroidSymbol, SFSymbol, SymbolViewProps } from "expo-symbols";
134import { withUniwind } from "uniwind";
135​
136const ANDROID_ICON_BY_SF_SYMBOL = {
137 plusminus: IconPlusMinus,
138 "git.pull-request.closed": IconGitPullRequestClosed,
139 "git.pull-request.draft": IconGitPullRequestDraft,
140 "git.commit": IconGitCommit,
141 "arrow.branch": IconGitBranch,
142 "arrow.left": IconArrowLeft,
143 "arrow.right": IconArrowRight,
144 "arrow.left.arrow.right": IconArrowsLeftRight,
145 "arrow.clockwise": IconRefresh,
146 "arrow.down": IconArrowDown,
147 "arrow.down.circle": IconArrowDownCircle,
148 "arrow.right.circle": IconArrowRightCircle,
149 "arrow.triangle.branch": IconGitBranch,
150 "arrow.triangle.merge": IconGitMerge,
151 "arrow.triangle.pull": IconGitPullRequest,
152 "square.3.layers.3d": IconStack2,
153 "arrow.turn.left.up": IconArrowBackUp,
154 "arrow.up": IconArrowUp,
155 "arrow.up.circle": IconArrowUpCircle,
156 "arrow.up.left.and.arrow.down.right": IconArrowsDiagonal2,
157 "arrow.down.right.and.arrow.up.left": IconArrowsMinimize,
158 "arrow.up.right": IconArrowUpRight,
159 "arrow.up.right.circle": IconArrowUpRightCircle,
160 "arrow.uturn.backward": IconArrowBackUp,
161 "arrow.uturn.forward": IconArrowForwardUp,
162 archivebox: IconArchive,
163 "archivebox.fill": IconArchive,
164 "bell.badge": IconBellRinging,
165 "bolt.circle": IconBolt,
166 "bolt.horizontal.circle": IconBolt,
167 brain: IconBrain,
168 "cable.connector": IconPlug,
169 camera: IconCamera,
170 car: IconCar,
171 "chart.bar.xaxis": IconChartBar,
172 checkmark: IconCheck,
173 "checkmark.circle": IconCircleCheck,
174 "checkmark.circle.fill": IconCircleCheck,
175 circle: IconCircle,
176 "circle.dashed": IconCircleDashed,
177 "circle.inset.filled": IconCircleDot,
178 clock: IconClock,
179 timer: IconClock,
180 ticket: IconTicket,
181 cloud: IconCloud,
182 cube: IconBox,
183 "chevron.down": IconChevronDown,
184 "chevron.left": IconChevronLeft,
185 "chevron.left.forwardslash.chevron.right": IconCode,
186 "chevron.right": IconChevronRight,
187 "chevron.up": IconChevronUp,
188 desktopcomputer: IconDeviceDesktop,
189 doc: IconFileText,
190 "doc.on.doc": IconCopy,
191 "doc.text": IconFileText,
192 "file.diff": IconFileDiff,
193 ellipsis: IconDots,
194 moon: IconMoon,
195 "ellipsis.circle": IconDotsCircleHorizontal,
196 "exclamationmark.triangle": IconAlertTriangle,
197 "exclamationmark.circle": IconAlertCircle,
198 eye: IconEye,
199 "eye.slash": IconEyeOff,
200 folder: IconFolder,
201 "folder.badge.plus": IconFolderPlus,
202 "folder.fill": IconFolder,
203 gearshape: IconSettings,
204 globe: IconWorld,
205 hammer: IconHammer,
206 headphones: IconHeadphones,
207 house: IconHome,
208 "info.circle": IconInfoCircle,
209 internaldrive: IconDatabase,
210 iphone: IconDeviceMobile,
211 keyboard: IconKeyboard,
212 laptopcomputer: IconDeviceLaptop,
213 link: IconLink,
214 "list.number": IconListNumbers,
215 "line.3.horizontal": IconMenu2,
216 "line.3.horizontal.decrease": IconFilter,
217 "line.3.horizontal.decrease.circle": IconFilter,
218 "line.3.horizontal.decrease.circle.fill": IconFilterFilled,
219 // Tabler has no Apple desktops; the closest silhouettes stand in on Android.
220 macmini: IconServer,
221 macstudio: IconDeviceDesktop,
222 magnifyingglass: IconSearch,
223 mic: IconMicrophone,
224 paintbrush: IconPalette,
225 pencil: IconPencil,
226 "person.crop.circle": IconUserCircle,
227 "person.2": IconUsers,
228 "person.fill.checkmark": IconUserCheck,
229 "person.fill.xmark": IconUserX,
230 "person.badge.clock": IconUserQuestion,
231 "person.badge.plus": IconUserPlus,
232 photo: IconPhoto,
233 pin: IconPin,
234 "pin.slash": IconPinnedOff,
235 play: IconPlayerPlay,
236 plus: IconPlus,
237 minus: IconMinus,
238 "qrcode.viewfinder": IconQrcode,
239 "point.3.connected.trianglepath.dotted": IconNetwork,
240 "point.topleft.down.curvedto.point.bottomright.up": IconGitMerge,
241 safari: IconExternalLink,
242 "server.rack": IconServer,
243 stethoscope: IconStethoscope,
244 "sidebar.left": IconLayoutSidebar,
245 "sidebar.right": IconLayoutSidebarRight,
246 "slider.horizontal.3": IconAdjustmentsHorizontal,
247 "square.and.pencil": IconEdit,
248 "square.on.square": IconCopy,
249 "square.grid.2x2": IconApps,
250 "square.split.2x1": IconLayoutColumns,
251 star: IconStar,
252 "star.fill": IconStarFilled,
253 "sun.max": IconSun,
254 "stop.fill": IconPlayerStopFilled,
255 target: IconTarget,
256 terminal: IconTerminal2,
257 "text.alignleft": IconAlignLeft,
258 "text.bubble": IconMessage,
259 "questionmark.bubble": IconMessageCircleQuestion,
260 "exclamationmark.shield": IconShieldQuestion,
261 "bubble.left.and.bubble.right": IconMessage,
262 "bubble.left": IconMessage,
263 sparkles: IconSparkles,
264 "plus.bubble": IconMessagePlus,
265 "text.word.spacing": IconLetterSpacing,
266 "textformat.size": IconTypography,
267 "textformat.size.larger": IconTextIncrease,
268 "textformat.size.smaller": IconTextDecrease,
269 "tray.and.arrow.up": IconUpload,
270 trash: IconTrash,
271 wifi: IconWifi,
272 "wifi.slash": IconWifiOff,
273 xmark: IconX,
274 "xmark.circle.fill": IconCircleXFilled,
275} satisfies Partial<
276 Record<
277 SFSymbol | "git.pull-request.closed" | "git.pull-request.draft" | "git.commit" | "file.diff",
278 Icon
279 >
280>;
281const SF_ICON_LOOKUP: Partial<
282 Record<
283 SFSymbol | "git.pull-request.closed" | "git.pull-request.draft" | "git.commit" | "file.diff",
284 Icon
285 >
286> = ANDROID_ICON_BY_SF_SYMBOL;
287​
288// Callers can pass `{ ios, android }` names where `android` is a Material
289// icon name (the raw expo-symbols contract). Resolve those here too so the
290// android key keeps working through this wrapper — it wins over the SF map
291// when both match (e.g. folder vs folder_open for expanded project groups).
292const ANDROID_ICON_BY_MATERIAL_NAME = {
293 auto_awesome: IconSparkles,
294 bolt: IconBolt,
295 build: IconTool,
296 chat: IconMessage,
297 chat_bubble: IconMessage,
298 check: IconCheck,
299 close: IconX,
300 construction: IconHammer,
301 content_copy: IconCopy,
302 desktop_windows: IconDeviceDesktop,
303 edit: IconEdit,
304 error: IconAlertCircle,
305 folder: IconFolder,
306 folder_open: IconFolderOpen,
307 keyboard: IconKeyboard,
308 keyboard_arrow_down: IconChevronDown,
309 keyboard_arrow_up: IconChevronUp,
310 keyboard_hide: IconKeyboardHide,
311 lock: IconLock,
312 more_vert: IconDotsVertical,
313 merge: IconGitMerge,
314 psychology: IconBrain,
315 public: IconWorld,
316 remove: IconMinus,
317 smartphone: IconDeviceMobile,
318 terminal: IconTerminal2,
319 visibility: IconEye,
320} satisfies Partial<Record<AndroidSymbol, Icon>>;
321​
322export type { SFSymbol } from "expo-symbols";
323export type AppSymbolName =
324 | keyof typeof ANDROID_ICON_BY_SF_SYMBOL
325 | {
326 ios: SFSymbol;
327 android: keyof typeof ANDROID_ICON_BY_MATERIAL_NAME;
328 };
329​
330export type AppSymbolViewProps = Omit<SymbolViewProps, "name"> & { name: AppSymbolName };
331​
332export function isAppSymbolName(name: string): name is Extract<AppSymbolName, string> {
333 return Object.prototype.hasOwnProperty.call(ANDROID_ICON_BY_SF_SYMBOL, name);
335​
336function AppSymbolView(props: AppSymbolViewProps) {
337 const materialName = typeof props.name === "string" ? undefined : props.name.android;
338 const sfSymbol = typeof props.name === "string" ? props.name : props.name.ios;
339 const AndroidIcon =
340 (materialName ? ANDROID_ICON_BY_MATERIAL_NAME[materialName] : undefined) ??
341 (sfSymbol ? SF_ICON_LOOKUP[sfSymbol] : undefined);
342​
343 if (!AndroidIcon) {
344 return props.fallback ?? null;
345 }
346​
347 return (
348 <AndroidIcon
349 accessibilityLabel={props.accessibilityLabel}
350 color={props.tintColor}
351 size={props.size}
352 strokeWidth={2}
353 style={props.style}
354 testID={props.testID}
355 />
356 );
358​
359/**
360 * expo-symbols and the Android Tabler fallback both expose tint as a native
361 * prop rather than a React Native style. Keep that third-party boundary here
362 * so callers can use Uniwind's `tintColorClassName` instead of subscribing to
363 * theme variables in every parent component.
364 */
365export const SymbolView = withUniwind(AppSymbolView);