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

AppSymbol.tsx

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