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

AppSymbol.tsx

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