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

AppSymbol.tsx

227 lines6.2 KB

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