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

AppSymbol.tsx

357 lines15.9 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 IconShare from "@tabler/icons-react-native/IconShare";
107import IconServer from "@tabler/icons-react-native/IconServer";
108import IconSettings from "@tabler/icons-react-native/IconSettings";
109import IconSparkles from "@tabler/icons-react-native/IconSparkles";
110import IconStack2 from "@tabler/icons-react-native/IconStack2";
111import IconStar from "@tabler/icons-react-native/IconStar";
112import IconStarFilled from "@tabler/icons-react-native/IconStarFilled";
113import IconStethoscope from "@tabler/icons-react-native/IconStethoscope";
114import IconSun from "@tabler/icons-react-native/IconSun";
115import IconShieldQuestion from "@tabler/icons-react-native/IconShieldQuestion";
116import IconTarget from "@tabler/icons-react-native/IconTarget";
117import IconTerminal2 from "@tabler/icons-react-native/IconTerminal2";
118import IconTextDecrease from "@tabler/icons-react-native/IconTextDecrease";
119import IconTextIncrease from "@tabler/icons-react-native/IconTextIncrease";
120import IconTool from "@tabler/icons-react-native/IconTool";
121import IconTrash from "@tabler/icons-react-native/IconTrash";
122import IconTypography from "@tabler/icons-react-native/IconTypography";
123import IconUpload from "@tabler/icons-react-native/IconUpload";
124import IconUserCircle from "@tabler/icons-react-native/IconUserCircle";
125import IconUserCheck from "@tabler/icons-react-native/IconUserCheck";
126import IconUserX from "@tabler/icons-react-native/IconUserX";
127import IconUserQuestion from "@tabler/icons-react-native/IconUserQuestion";
128import IconUserPlus from "@tabler/icons-react-native/IconUserPlus";
129import IconUsers from "@tabler/icons-react-native/IconUsers";
130import IconWifi from "@tabler/icons-react-native/IconWifi";
131import IconWifiOff from "@tabler/icons-react-native/IconWifiOff";
132import IconWorld from "@tabler/icons-react-native/IconWorld";
133import IconX from "@tabler/icons-react-native/IconX";
134import type { AndroidSymbol, SFSymbol, SymbolViewProps } from "expo-symbols";
135import { withUniwind } from "uniwind";
136​
137const ANDROID_ICON_BY_SF_SYMBOL = {
138 plusminus: IconPlusMinus,
139 "git.pull-request.closed": IconGitPullRequestClosed,
140 "git.pull-request.draft": IconGitPullRequestDraft,
141 "git.commit": IconGitCommit,
142 "arrow.branch": IconGitBranch,
143 "arrow.left": IconArrowLeft,
144 "arrow.right": IconArrowRight,
145 "arrow.left.arrow.right": IconArrowsLeftRight,
146 "arrow.clockwise": IconRefresh,
147 "arrow.down": IconArrowDown,
148 "arrow.down.circle": IconArrowDownCircle,
149 "arrow.right.circle": IconArrowRightCircle,
150 "arrow.triangle.branch": IconGitBranch,
151 "arrow.triangle.merge": IconGitMerge,
152 "arrow.triangle.pull": IconGitPullRequest,
153 "square.3.layers.3d": IconStack2,
154 "arrow.turn.left.up": IconArrowBackUp,
155 "arrow.up": IconArrowUp,
156 "arrow.up.circle": IconArrowUpCircle,
157 "arrow.up.left.and.arrow.down.right": IconArrowsDiagonal2,
158 "arrow.down.right.and.arrow.up.left": IconArrowsMinimize,
159 "arrow.up.right": IconArrowUpRight,
160 "arrow.up.right.circle": IconArrowUpRightCircle,
161 "arrow.uturn.backward": IconArrowBackUp,
162 "arrow.uturn.forward": IconArrowForwardUp,
163 archivebox: IconArchive,
164 "archivebox.fill": IconArchive,
165 "bell.badge": IconBellRinging,
166 "bolt.circle": IconBolt,
167 "bolt.horizontal.circle": IconBolt,
168 brain: IconBrain,
169 "cable.connector": IconPlug,
170 camera: IconCamera,
171 car: IconCar,
172 "chart.bar.xaxis": IconChartBar,
173 checkmark: IconCheck,
174 "checkmark.circle": IconCircleCheck,
175 "checkmark.circle.fill": IconCircleCheck,
176 circle: IconCircle,
177 "circle.dashed": IconCircleDashed,
178 "circle.inset.filled": IconCircleDot,
179 "circle.dashed.inset.filled": IconCircleDot,
180 clock: IconClock,
181 timer: IconClock,
182 ticket: IconTicket,
183 cloud: IconCloud,
184 cube: IconBox,
185 "chevron.down": IconChevronDown,
186 "chevron.left": IconChevronLeft,
187 "chevron.left.forwardslash.chevron.right": IconCode,
188 "chevron.right": IconChevronRight,
189 "chevron.up": IconChevronUp,
190 desktopcomputer: IconDeviceDesktop,
191 doc: IconFileText,
192 "doc.on.doc": IconCopy,
193 "doc.text": IconFileText,
194 "file.diff": IconFileDiff,
195 ellipsis: IconDots,
196 moon: IconMoon,
197 "ellipsis.circle": IconDotsCircleHorizontal,
198 "exclamationmark.triangle": IconAlertTriangle,
199 "exclamationmark.circle": IconAlertCircle,
200 eye: IconEye,
201 "eye.slash": IconEyeOff,
202 folder: IconFolder,
203 "folder.badge.plus": IconFolderPlus,
204 "folder.fill": IconFolder,
205 gearshape: IconSettings,
206 globe: IconWorld,
207 hammer: IconHammer,
208 headphones: IconHeadphones,
209 house: IconHome,
210 "info.circle": IconInfoCircle,
211 internaldrive: IconDatabase,
212 iphone: IconDeviceMobile,
213 keyboard: IconKeyboard,
214 laptopcomputer: IconDeviceLaptop,
215 link: IconLink,
216 "list.number": IconListNumbers,
217 "line.3.horizontal": IconMenu2,
218 "line.3.horizontal.decrease": IconFilter,
219 "line.3.horizontal.decrease.circle": IconFilter,
220 "line.3.horizontal.decrease.circle.fill": IconFilterFilled,
221 macmini: IconServer,
222 macstudio: IconDeviceDesktop,
223 magnifyingglass: IconSearch,
224 mic: IconMicrophone,
225 paintbrush: IconPalette,
226 pencil: IconPencil,
227 "person.crop.circle": IconUserCircle,
228 "person.2": IconUsers,
229 "person.fill.checkmark": IconUserCheck,
230 "person.fill.xmark": IconUserX,
231 "person.badge.clock": IconUserQuestion,
232 "person.badge.plus": IconUserPlus,
233 photo: IconPhoto,
234 pin: IconPin,
235 "pin.slash": IconPinnedOff,
236 play: IconPlayerPlay,
237 plus: IconPlus,
238 minus: IconMinus,
239 "qrcode.viewfinder": IconQrcode,
240 "point.3.connected.trianglepath.dotted": IconNetwork,
241 "point.topleft.down.curvedto.point.bottomright.up": IconGitMerge,
242 safari: IconExternalLink,
243 "server.rack": IconServer,
244 stethoscope: IconStethoscope,
245 "sidebar.left": IconLayoutSidebar,
246 "sidebar.right": IconLayoutSidebarRight,
247 "slider.horizontal.3": IconAdjustmentsHorizontal,
248 "square.and.arrow.up": IconShare,
249 "square.and.pencil": IconEdit,
250 "square.on.square": IconCopy,
251 "square.grid.2x2": IconApps,
252 "square.split.2x1": IconLayoutColumns,
253 star: IconStar,
254 "star.fill": IconStarFilled,
255 "sun.max": IconSun,
256 "stop.fill": IconPlayerStopFilled,
257 target: IconTarget,
258 terminal: IconTerminal2,
259 "text.alignleft": IconAlignLeft,
260 "text.bubble": IconMessage,
261 "questionmark.bubble": IconMessageCircleQuestion,
262 "exclamationmark.shield": IconShieldQuestion,
263 "bubble.left.and.bubble.right": IconMessage,
264 "bubble.left": IconMessage,
265 sparkles: IconSparkles,
266 "plus.bubble": IconMessagePlus,
267 "text.word.spacing": IconLetterSpacing,
268 "textformat.size": IconTypography,
269 "textformat.size.larger": IconTextIncrease,
270 "textformat.size.smaller": IconTextDecrease,
271 "tray.and.arrow.up": IconUpload,
272 trash: IconTrash,
273 wifi: IconWifi,
274 "wifi.slash": IconWifiOff,
275 xmark: IconX,
276 "xmark.circle.fill": IconCircleXFilled,
277} satisfies Partial<
278 Record<
279 SFSymbol | "git.pull-request.closed" | "git.pull-request.draft" | "git.commit" | "file.diff",
280 Icon
281 >
282>;
283const SF_ICON_LOOKUP: Partial<
284 Record<
285 SFSymbol | "git.pull-request.closed" | "git.pull-request.draft" | "git.commit" | "file.diff",
286 Icon
287 >
288> = ANDROID_ICON_BY_SF_SYMBOL;
289​
290const ANDROID_ICON_BY_MATERIAL_NAME = {
291 auto_awesome: IconSparkles,
292 bolt: IconBolt,
293 build: IconTool,
294 chat: IconMessage,
295 chat_bubble: IconMessage,
296 check: IconCheck,
297 close: IconX,
298 construction: IconHammer,
299 content_copy: IconCopy,
300 desktop_windows: IconDeviceDesktop,
301 edit: IconEdit,
302 error: IconAlertCircle,
303 folder: IconFolder,
304 folder_open: IconFolderOpen,
305 keyboard: IconKeyboard,
306 keyboard_arrow_down: IconChevronDown,
307 keyboard_arrow_up: IconChevronUp,
308 keyboard_hide: IconKeyboardHide,
309 lock: IconLock,
310 more_vert: IconDotsVertical,
311 merge: IconGitMerge,
312 psychology: IconBrain,
313 public: IconWorld,
314 remove: IconMinus,
315 smartphone: IconDeviceMobile,
316 terminal: IconTerminal2,
317 visibility: IconEye,
318} satisfies Partial<Record<AndroidSymbol, Icon>>;
319​
320export type { SFSymbol } from "expo-symbols";
321export type AppSymbolName =
322 | keyof typeof ANDROID_ICON_BY_SF_SYMBOL
323 | {
324 ios: SFSymbol;
325 android: keyof typeof ANDROID_ICON_BY_MATERIAL_NAME;
326 };
327​
328export type AppSymbolViewProps = Omit<SymbolViewProps, "name"> & { name: AppSymbolName };
329​
330export function isAppSymbolName(name: string): name is Extract<AppSymbolName, string> {
331 return Object.prototype.hasOwnProperty.call(ANDROID_ICON_BY_SF_SYMBOL, name);
333​
334function AppSymbolView(props: AppSymbolViewProps) {
335 const materialName = typeof props.name === "string" ? undefined : props.name.android;
336 const sfSymbol = typeof props.name === "string" ? props.name : props.name.ios;
337 const AndroidIcon =
338 (materialName ? ANDROID_ICON_BY_MATERIAL_NAME[materialName] : undefined) ??
339 (sfSymbol ? SF_ICON_LOOKUP[sfSymbol] : undefined);
340​
341 if (!AndroidIcon) {
342 return props.fallback ?? null;
343 }
344​
345 return (
346 <AndroidIcon
347 accessibilityLabel={props.accessibilityLabel}
348 color={props.tintColor}
349 size={props.size}
350 strokeWidth={2}
351 style={props.style}
352 testID={props.testID}
353 />
354 );
356​
357export const SymbolView = withUniwind(AppSymbolView);