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

AppSymbol.tsx

359 lines16.0 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 IconBan from "@tabler/icons-react-native/IconBan";
27import IconBellRinging from "@tabler/icons-react-native/IconBellRinging";
28import IconBolt from "@tabler/icons-react-native/IconBolt";
29import IconBox from "@tabler/icons-react-native/IconBox";
30import IconBrain from "@tabler/icons-react-native/IconBrain";
31import IconCamera from "@tabler/icons-react-native/IconCamera";
32import IconCar from "@tabler/icons-react-native/IconCar";
33import IconChartBar from "@tabler/icons-react-native/IconChartBar";
34import IconCheck from "@tabler/icons-react-native/IconCheck";
35import IconCloud from "@tabler/icons-react-native/IconCloud";
36import IconChevronDown from "@tabler/icons-react-native/IconChevronDown";
37import IconChevronLeft from "@tabler/icons-react-native/IconChevronLeft";
38import IconChevronRight from "@tabler/icons-react-native/IconChevronRight";
39import IconChevronUp from "@tabler/icons-react-native/IconChevronUp";
40import IconCircle from "@tabler/icons-react-native/IconCircle";
41import IconCircleCheck from "@tabler/icons-react-native/IconCircleCheck";
42import IconCircleDashed from "@tabler/icons-react-native/IconCircleDashed";
43import IconCircleDot from "@tabler/icons-react-native/IconCircleDot";
44import IconCircleXFilled from "@tabler/icons-react-native/IconCircleXFilled";
45import IconTicket from "@tabler/icons-react-native/IconTicket";
46import IconClock from "@tabler/icons-react-native/IconClock";
47import IconCode from "@tabler/icons-react-native/IconCode";
48import IconCopy from "@tabler/icons-react-native/IconCopy";
49import IconDatabase from "@tabler/icons-react-native/IconDatabase";
50import IconDeviceDesktop from "@tabler/icons-react-native/IconDeviceDesktop";
51import IconDeviceLaptop from "@tabler/icons-react-native/IconDeviceLaptop";
52import IconDeviceMobile from "@tabler/icons-react-native/IconDeviceMobile";
53import IconDots from "@tabler/icons-react-native/IconDots";
54import IconPlusMinus from "@tabler/icons-react-native/IconPlusMinus";
55import IconDotsVertical from "@tabler/icons-react-native/IconDotsVertical";
56import IconDotsCircleHorizontal from "@tabler/icons-react-native/IconDotsCircleHorizontal";
57import IconEdit from "@tabler/icons-react-native/IconEdit";
58import IconExternalLink from "@tabler/icons-react-native/IconExternalLink";
59import IconEyeOff from "@tabler/icons-react-native/IconEyeOff";
60import IconEye from "@tabler/icons-react-native/IconEye";
61import IconFileText from "@tabler/icons-react-native/IconFileText";
62import IconFileDiff from "@tabler/icons-react-native/IconFileDiff";
63import IconFilter from "@tabler/icons-react-native/IconFilter";
64import IconFilterFilled from "@tabler/icons-react-native/IconFilterFilled";
65import IconFolder from "@tabler/icons-react-native/IconFolder";
66import IconFolderOpen from "@tabler/icons-react-native/IconFolderOpen";
67import IconHeadphones from "@tabler/icons-react-native/IconHeadphones";
68import IconFolderPlus from "@tabler/icons-react-native/IconFolderPlus";
69import IconGitPullRequestClosed from "@tabler/icons-react-native/IconGitPullRequestClosed";
70import IconGitPullRequestDraft from "@tabler/icons-react-native/IconGitPullRequestDraft";
71import IconGitCommit from "@tabler/icons-react-native/IconGitCommit";
72import IconGitBranch from "@tabler/icons-react-native/IconGitBranch";
73import IconGitMerge from "@tabler/icons-react-native/IconGitMerge";
74import IconGitPullRequest from "@tabler/icons-react-native/IconGitPullRequest";
75import IconHammer from "@tabler/icons-react-native/IconHammer";
76import IconHome from "@tabler/icons-react-native/IconHome";
77import IconInfoCircle from "@tabler/icons-react-native/IconInfoCircle";
78import IconKeyboard from "@tabler/icons-react-native/IconKeyboard";
79import IconKeyboardHide from "@tabler/icons-react-native/IconKeyboardHide";
80import IconLock from "@tabler/icons-react-native/IconLock";
81import IconLayoutColumns from "@tabler/icons-react-native/IconLayoutColumns";
82import IconLayoutSidebar from "@tabler/icons-react-native/IconLayoutSidebar";
83import IconLayoutSidebarRight from "@tabler/icons-react-native/IconLayoutSidebarRight";
84import IconLetterSpacing from "@tabler/icons-react-native/IconLetterSpacing";
85import IconMicrophone from "@tabler/icons-react-native/IconMicrophone";
86import IconLink from "@tabler/icons-react-native/IconLink";
87import IconListNumbers from "@tabler/icons-react-native/IconListNumbers";
88import IconMenu2 from "@tabler/icons-react-native/IconMenu2";
89import IconMessageCircleQuestion from "@tabler/icons-react-native/IconMessageCircleQuestion";
90import IconMessage from "@tabler/icons-react-native/IconMessage";
91import IconMessagePlus from "@tabler/icons-react-native/IconMessagePlus";
92import IconMinus from "@tabler/icons-react-native/IconMinus";
93import IconMoon from "@tabler/icons-react-native/IconMoon";
94import IconNetwork from "@tabler/icons-react-native/IconNetwork";
95import IconPalette from "@tabler/icons-react-native/IconPalette";
96import IconPencil from "@tabler/icons-react-native/IconPencil";
97import IconPlug from "@tabler/icons-react-native/IconPlug";
98import IconPhoto from "@tabler/icons-react-native/IconPhoto";
99import IconPin from "@tabler/icons-react-native/IconPin";
100import IconPinnedOff from "@tabler/icons-react-native/IconPinnedOff";
101import IconPlayerPlay from "@tabler/icons-react-native/IconPlayerPlay";
102import IconPlayerStopFilled from "@tabler/icons-react-native/IconPlayerStopFilled";
103import IconPlus from "@tabler/icons-react-native/IconPlus";
104import IconQrcode from "@tabler/icons-react-native/IconQrcode";
105import IconRefresh from "@tabler/icons-react-native/IconRefresh";
106import IconSearch from "@tabler/icons-react-native/IconSearch";
107import IconShare from "@tabler/icons-react-native/IconShare";
108import IconServer from "@tabler/icons-react-native/IconServer";
109import IconSettings from "@tabler/icons-react-native/IconSettings";
110import IconSparkles from "@tabler/icons-react-native/IconSparkles";
111import IconStack2 from "@tabler/icons-react-native/IconStack2";
112import IconStar from "@tabler/icons-react-native/IconStar";
113import IconStarFilled from "@tabler/icons-react-native/IconStarFilled";
114import IconStethoscope from "@tabler/icons-react-native/IconStethoscope";
115import IconSun from "@tabler/icons-react-native/IconSun";
116import IconShieldQuestion from "@tabler/icons-react-native/IconShieldQuestion";
117import IconTarget from "@tabler/icons-react-native/IconTarget";
118import IconTerminal2 from "@tabler/icons-react-native/IconTerminal2";
119import IconTextDecrease from "@tabler/icons-react-native/IconTextDecrease";
120import IconTextIncrease from "@tabler/icons-react-native/IconTextIncrease";
121import IconTool from "@tabler/icons-react-native/IconTool";
122import IconTrash from "@tabler/icons-react-native/IconTrash";
123import IconTypography from "@tabler/icons-react-native/IconTypography";
124import IconUpload from "@tabler/icons-react-native/IconUpload";
125import IconUserCircle from "@tabler/icons-react-native/IconUserCircle";
126import IconUserCheck from "@tabler/icons-react-native/IconUserCheck";
127import IconUserX from "@tabler/icons-react-native/IconUserX";
128import IconUserQuestion from "@tabler/icons-react-native/IconUserQuestion";
129import IconUserPlus from "@tabler/icons-react-native/IconUserPlus";
130import IconUsers from "@tabler/icons-react-native/IconUsers";
131import IconWifi from "@tabler/icons-react-native/IconWifi";
132import IconWifiOff from "@tabler/icons-react-native/IconWifiOff";
133import IconWorld from "@tabler/icons-react-native/IconWorld";
134import IconX from "@tabler/icons-react-native/IconX";
135import type { AndroidSymbol, SFSymbol, SymbolViewProps } from "expo-symbols";
136import { withUniwind } from "uniwind";
137​
138const ANDROID_ICON_BY_SF_SYMBOL = {
139 plusminus: IconPlusMinus,
140 "git.pull-request.closed": IconGitPullRequestClosed,
141 "git.pull-request.draft": IconGitPullRequestDraft,
142 "git.commit": IconGitCommit,
143 "arrow.branch": IconGitBranch,
144 "arrow.left": IconArrowLeft,
145 "arrow.right": IconArrowRight,
146 "arrow.left.arrow.right": IconArrowsLeftRight,
147 "arrow.clockwise": IconRefresh,
148 "arrow.down": IconArrowDown,
149 "arrow.down.circle": IconArrowDownCircle,
150 "arrow.right.circle": IconArrowRightCircle,
151 "arrow.triangle.branch": IconGitBranch,
152 "arrow.triangle.merge": IconGitMerge,
153 "arrow.triangle.pull": IconGitPullRequest,
154 "square.3.layers.3d": IconStack2,
155 "arrow.turn.left.up": IconArrowBackUp,
156 "arrow.up": IconArrowUp,
157 "arrow.up.circle": IconArrowUpCircle,
158 "arrow.up.left.and.arrow.down.right": IconArrowsDiagonal2,
159 "arrow.down.right.and.arrow.up.left": IconArrowsMinimize,
160 "arrow.up.right": IconArrowUpRight,
161 "arrow.up.right.circle": IconArrowUpRightCircle,
162 "arrow.uturn.backward": IconArrowBackUp,
163 "arrow.uturn.forward": IconArrowForwardUp,
164 archivebox: IconArchive,
165 "archivebox.fill": IconArchive,
166 "bell.badge": IconBellRinging,
167 "bolt.circle": IconBolt,
168 "bolt.horizontal.circle": IconBolt,
169 brain: IconBrain,
170 "cable.connector": IconPlug,
171 camera: IconCamera,
172 car: IconCar,
173 "chart.bar.xaxis": IconChartBar,
174 checkmark: IconCheck,
175 "checkmark.circle": IconCircleCheck,
176 "checkmark.circle.fill": IconCircleCheck,
177 circle: IconCircle,
178 "circle.dashed": IconCircleDashed,
179 "circle.inset.filled": IconCircleDot,
180 "circle.dashed.inset.filled": IconCircleDot,
181 clock: IconClock,
182 timer: IconClock,
183 ticket: IconTicket,
184 cloud: IconCloud,
185 cube: IconBox,
186 "chevron.down": IconChevronDown,
187 "chevron.left": IconChevronLeft,
188 "chevron.left.forwardslash.chevron.right": IconCode,
189 "chevron.right": IconChevronRight,
190 "chevron.up": IconChevronUp,
191 desktopcomputer: IconDeviceDesktop,
192 doc: IconFileText,
193 "doc.on.doc": IconCopy,
194 "doc.text": IconFileText,
195 "file.diff": IconFileDiff,
196 ellipsis: IconDots,
197 moon: IconMoon,
198 "ellipsis.circle": IconDotsCircleHorizontal,
199 "exclamationmark.triangle": IconAlertTriangle,
200 "exclamationmark.circle": IconAlertCircle,
201 eye: IconEye,
202 "eye.slash": IconEyeOff,
203 folder: IconFolder,
204 "folder.badge.plus": IconFolderPlus,
205 "folder.fill": IconFolder,
206 gearshape: IconSettings,
207 globe: IconWorld,
208 hammer: IconHammer,
209 headphones: IconHeadphones,
210 house: IconHome,
211 "info.circle": IconInfoCircle,
212 internaldrive: IconDatabase,
213 iphone: IconDeviceMobile,
214 keyboard: IconKeyboard,
215 laptopcomputer: IconDeviceLaptop,
216 link: IconLink,
217 "list.number": IconListNumbers,
218 "line.3.horizontal": IconMenu2,
219 "line.3.horizontal.decrease": IconFilter,
220 "line.3.horizontal.decrease.circle": IconFilter,
221 "line.3.horizontal.decrease.circle.fill": IconFilterFilled,
222 macmini: IconServer,
223 macstudio: IconDeviceDesktop,
224 magnifyingglass: IconSearch,
225 mic: IconMicrophone,
226 paintbrush: IconPalette,
227 pencil: IconPencil,
228 "person.crop.circle": IconUserCircle,
229 "person.2": IconUsers,
230 "person.fill.checkmark": IconUserCheck,
231 "person.fill.xmark": IconUserX,
232 "person.badge.clock": IconUserQuestion,
233 "person.badge.plus": IconUserPlus,
234 photo: IconPhoto,
235 pin: IconPin,
236 "pin.slash": IconPinnedOff,
237 play: IconPlayerPlay,
238 plus: IconPlus,
239 minus: IconMinus,
240 "slash.circle": IconBan,
241 "qrcode.viewfinder": IconQrcode,
242 "point.3.connected.trianglepath.dotted": IconNetwork,
243 "point.topleft.down.curvedto.point.bottomright.up": IconGitMerge,
244 safari: IconExternalLink,
245 "server.rack": IconServer,
246 stethoscope: IconStethoscope,
247 "sidebar.left": IconLayoutSidebar,
248 "sidebar.right": IconLayoutSidebarRight,
249 "slider.horizontal.3": IconAdjustmentsHorizontal,
250 "square.and.arrow.up": IconShare,
251 "square.and.pencil": IconEdit,
252 "square.on.square": IconCopy,
253 "square.grid.2x2": IconApps,
254 "square.split.2x1": IconLayoutColumns,
255 star: IconStar,
256 "star.fill": IconStarFilled,
257 "sun.max": IconSun,
258 "stop.fill": IconPlayerStopFilled,
259 target: IconTarget,
260 terminal: IconTerminal2,
261 "text.alignleft": IconAlignLeft,
262 "text.bubble": IconMessage,
263 "questionmark.bubble": IconMessageCircleQuestion,
264 "exclamationmark.shield": IconShieldQuestion,
265 "bubble.left.and.bubble.right": IconMessage,
266 "bubble.left": IconMessage,
267 sparkles: IconSparkles,
268 "plus.bubble": IconMessagePlus,
269 "text.word.spacing": IconLetterSpacing,
270 "textformat.size": IconTypography,
271 "textformat.size.larger": IconTextIncrease,
272 "textformat.size.smaller": IconTextDecrease,
273 "tray.and.arrow.up": IconUpload,
274 trash: IconTrash,
275 wifi: IconWifi,
276 "wifi.slash": IconWifiOff,
277 xmark: IconX,
278 "xmark.circle.fill": IconCircleXFilled,
279} satisfies Partial<
280 Record<
281 SFSymbol | "git.pull-request.closed" | "git.pull-request.draft" | "git.commit" | "file.diff",
282 Icon
283 >
284>;
285const SF_ICON_LOOKUP: Partial<
286 Record<
287 SFSymbol | "git.pull-request.closed" | "git.pull-request.draft" | "git.commit" | "file.diff",
288 Icon
289 >
290> = ANDROID_ICON_BY_SF_SYMBOL;
291​
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​
359export const SymbolView = withUniwind(AppSymbolView);