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

AppSymbol.tsx

355 lines15.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 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 "circle.dashed.inset.filled": IconCircleDot,
179 clock: IconClock,
180 timer: IconClock,
181 ticket: IconTicket,
182 cloud: IconCloud,
183 cube: IconBox,
184 "chevron.down": IconChevronDown,
185 "chevron.left": IconChevronLeft,
186 "chevron.left.forwardslash.chevron.right": IconCode,
187 "chevron.right": IconChevronRight,
188 "chevron.up": IconChevronUp,
189 desktopcomputer: IconDeviceDesktop,
190 doc: IconFileText,
191 "doc.on.doc": IconCopy,
192 "doc.text": IconFileText,
193 "file.diff": IconFileDiff,
194 ellipsis: IconDots,
195 moon: IconMoon,
196 "ellipsis.circle": IconDotsCircleHorizontal,
197 "exclamationmark.triangle": IconAlertTriangle,
198 "exclamationmark.circle": IconAlertCircle,
199 eye: IconEye,
200 "eye.slash": IconEyeOff,
201 folder: IconFolder,
202 "folder.badge.plus": IconFolderPlus,
203 "folder.fill": IconFolder,
204 gearshape: IconSettings,
205 globe: IconWorld,
206 hammer: IconHammer,
207 headphones: IconHeadphones,
208 house: IconHome,
209 "info.circle": IconInfoCircle,
210 internaldrive: IconDatabase,
211 iphone: IconDeviceMobile,
212 keyboard: IconKeyboard,
213 laptopcomputer: IconDeviceLaptop,
214 link: IconLink,
215 "list.number": IconListNumbers,
216 "line.3.horizontal": IconMenu2,
217 "line.3.horizontal.decrease": IconFilter,
218 "line.3.horizontal.decrease.circle": IconFilter,
219 "line.3.horizontal.decrease.circle.fill": IconFilterFilled,
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​
288const ANDROID_ICON_BY_MATERIAL_NAME = {
289 auto_awesome: IconSparkles,
290 bolt: IconBolt,
291 build: IconTool,
292 chat: IconMessage,
293 chat_bubble: IconMessage,
294 check: IconCheck,
295 close: IconX,
296 construction: IconHammer,
297 content_copy: IconCopy,
298 desktop_windows: IconDeviceDesktop,
299 edit: IconEdit,
300 error: IconAlertCircle,
301 folder: IconFolder,
302 folder_open: IconFolderOpen,
303 keyboard: IconKeyboard,
304 keyboard_arrow_down: IconChevronDown,
305 keyboard_arrow_up: IconChevronUp,
306 keyboard_hide: IconKeyboardHide,
307 lock: IconLock,
308 more_vert: IconDotsVertical,
309 merge: IconGitMerge,
310 psychology: IconBrain,
311 public: IconWorld,
312 remove: IconMinus,
313 smartphone: IconDeviceMobile,
314 terminal: IconTerminal2,
315 visibility: IconEye,
316} satisfies Partial<Record<AndroidSymbol, Icon>>;
317​
318export type { SFSymbol } from "expo-symbols";
319export type AppSymbolName =
320 | keyof typeof ANDROID_ICON_BY_SF_SYMBOL
321 | {
322 ios: SFSymbol;
323 android: keyof typeof ANDROID_ICON_BY_MATERIAL_NAME;
324 };
325​
326export type AppSymbolViewProps = Omit<SymbolViewProps, "name"> & { name: AppSymbolName };
327​
328export function isAppSymbolName(name: string): name is Extract<AppSymbolName, string> {
329 return Object.prototype.hasOwnProperty.call(ANDROID_ICON_BY_SF_SYMBOL, name);
331​
332function AppSymbolView(props: AppSymbolViewProps) {
333 const materialName = typeof props.name === "string" ? undefined : props.name.android;
334 const sfSymbol = typeof props.name === "string" ? props.name : props.name.ios;
335 const AndroidIcon =
336 (materialName ? ANDROID_ICON_BY_MATERIAL_NAME[materialName] : undefined) ??
337 (sfSymbol ? SF_ICON_LOOKUP[sfSymbol] : undefined);
338​
339 if (!AndroidIcon) {
340 return props.fallback ?? null;
341 }
342​
343 return (
344 <AndroidIcon
345 accessibilityLabel={props.accessibilityLabel}
346 color={props.tintColor}
347 size={props.size}
348 strokeWidth={2}
349 style={props.style}
350 testID={props.testID}
351 />
352 );
354​
355export const SymbolView = withUniwind(AppSymbolView);