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

AppSymbol.tsx

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