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

AppSymbol.tsx

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