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 IconHash from "@tabler/icons-react-native/IconHash";
56import IconInfoCircle from "@tabler/icons-react-native/IconInfoCircle";
57import IconKeyboard from "@tabler/icons-react-native/IconKeyboard";
58import IconKeyboardHide from "@tabler/icons-react-native/IconKeyboardHide";
59import IconLayoutColumns from "@tabler/icons-react-native/IconLayoutColumns";
60import IconLayoutSidebar from "@tabler/icons-react-native/IconLayoutSidebar";
61import IconLayoutSidebarRight from "@tabler/icons-react-native/IconLayoutSidebarRight";
62import IconLetterSpacing from "@tabler/icons-react-native/IconLetterSpacing";
63import IconLink from "@tabler/icons-react-native/IconLink";
64import IconMail from "@tabler/icons-react-native/IconMail";
65import IconMessage from "@tabler/icons-react-native/IconMessage";
66import IconMinus from "@tabler/icons-react-native/IconMinus";
67import IconMoon from "@tabler/icons-react-native/IconMoon";
68import IconNetwork from "@tabler/icons-react-native/IconNetwork";
69import IconPalette from "@tabler/icons-react-native/IconPalette";
70import IconPhoto from "@tabler/icons-react-native/IconPhoto";
71import IconPin from "@tabler/icons-react-native/IconPin";
72import IconPinnedOff from "@tabler/icons-react-native/IconPinnedOff";
73import IconPlayerPlay from "@tabler/icons-react-native/IconPlayerPlay";
74import IconPlayerStopFilled from "@tabler/icons-react-native/IconPlayerStopFilled";
75import IconPlus from "@tabler/icons-react-native/IconPlus";
76import IconQrcode from "@tabler/icons-react-native/IconQrcode";
77import IconRefresh from "@tabler/icons-react-native/IconRefresh";
78import IconSearch from "@tabler/icons-react-native/IconSearch";
79import IconServer from "@tabler/icons-react-native/IconServer";
80import IconSettings from "@tabler/icons-react-native/IconSettings";
81import IconSparkles from "@tabler/icons-react-native/IconSparkles";
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 "arrow.turn.left.up": IconArrowBackUp,
105 "arrow.up": IconArrowUp,
106 "arrow.up.circle": IconArrowUpCircle,
107 "arrow.up.left.and.arrow.down.right": IconArrowsMaximize,
108 "arrow.down.right.and.arrow.up.left": IconArrowsMinimize,
109 "arrow.up.right": IconArrowUpRight,
110 "arrow.up.right.circle": IconArrowUpRightCircle,
111 "arrow.uturn.backward": IconArrowBackUp,
112 archivebox: IconArchive,
113 "archivebox.fill": IconArchive,
114 "bell.badge": IconBellRinging,
115 "bolt.circle": IconBolt,
116 "bolt.horizontal.circle": IconBolt,
117 brain: IconBrain,
118 camera: IconCamera,
119 "chart.bar.xaxis": IconChartBar,
120 checkmark: IconCheck,
121 "checkmark.circle": IconCircleCheck,
122 clock: IconClock,
123 ticket: IconTicket,
124 cloud: IconCloud,
125 cube: IconBox,
126 "chevron.down": IconChevronDown,
127 "chevron.left": IconChevronLeft,
128 "chevron.left.forwardslash.chevron.right": IconCode,
129 "chevron.right": IconChevronRight,
130 "chevron.up": IconChevronUp,
131 desktopcomputer: IconDeviceDesktop,
132 "doc.on.doc": IconCopy,
133 "envelope.badge": IconMail,
134 "doc.text": IconFileText,
135 number: IconHash,
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.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);