eletrotupi / tcc/ frontend/components/ui/icon-symbol.tsx6e7ecd390ce119d438ab5b3ab16fa1d9edeb434a
1.4 KB | 42 lines Raw
1
// Fallback for using MaterialIcons on Android and web.
2

3
import MaterialIcons from '@expo/vector-icons/MaterialIcons';
4
import { SymbolWeight, SymbolViewProps } from 'expo-symbols';
5
import { ComponentProps } from 'react';
6
import { OpaqueColorValue, type StyleProp, type TextStyle } from 'react-native';
7

8
type IconMapping = Record<SymbolViewProps['name'], ComponentProps<typeof MaterialIcons>['name']>;
9
type IconSymbolName = keyof typeof MAPPING;
10

11
/**
12
 * Add your SF Symbols to Material Icons mappings here.
13
 * - see Material Icons in the [Icons Directory](https://icons.expo.fyi).
14
 * - see SF Symbols in the [SF Symbols](https://developer.apple.com/sf-symbols/) app.
15
 */
16
const MAPPING = {
17
  'house.fill': 'home',
18
  'paperplane.fill': 'send',
19
  'chevron.left.forwardslash.chevron.right': 'code',
20
  'chevron.right': 'chevron-right',
21
  'settings.fill': 'settings'
22
} as IconMapping;
23

24
/**
25
 * An icon component that uses native SF Symbols on iOS, and Material Icons on Android and web.
26
 * This ensures a consistent look across platforms, and optimal resource usage.
27
 * Icon `name`s are based on SF Symbols and require manual mapping to Material Icons.
28
 */
29
export function IconSymbol({
30
  name,
31
  size = 24,
32
  color,
33
  style,
34
}: {
35
  name: IconSymbolName;
36
  size?: number;
37
  color: string | OpaqueColorValue;
38
  style?: StyleProp<TextStyle>;
39
  weight?: SymbolWeight;
40
}) {
41
  return <MaterialIcons color={color} size={size} name={MAPPING[name]} style={style} />;
42
}