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

AppSymbol.tsx

210 lines5.7 KB

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