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

AppSymbol.tsx

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