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

AppSymbol.tsx

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