| 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 | * TODO: We might get rid of this completely and just wrap a <MeterialIcons>
|
| 17 | * since we won't have iOS stuff
|
| 18 | */
|
| 19 | const MAPPING = {
|
| 20 | 'house.fill': 'home',
|
| 21 | 'add-circle': 'add-circle',
|
| 22 | 'history': 'history',
|
| 23 | 'lightbulb-outline': 'lightbulb-outline',
|
| 24 | 'paperplane.fill': 'send',
|
| 25 | 'chevron.left.forwardslash.chevron.right': 'code',
|
| 26 | 'chevron.right': 'chevron-right',
|
| 27 | 'bolt': 'bolt',
|
| 28 | 'settings.fill': 'settings'
|
| 29 | } as IconMapping;
|
| 30 |
|
| 31 | /**
|
| 32 | * An icon component that uses native SF Symbols on iOS, and Material Icons on Android and web.
|
| 33 | * This ensures a consistent look across platforms, and optimal resource usage.
|
| 34 | * Icon `name`s are based on SF Symbols and require manual mapping to Material Icons.
|
| 35 | */
|
| 36 | export function IconSymbol({
|
| 37 | name,
|
| 38 | size = 24,
|
| 39 | color,
|
| 40 | style,
|
| 41 | }: {
|
| 42 | name: IconSymbolName;
|
| 43 | size?: number;
|
| 44 | color: string | OpaqueColorValue;
|
| 45 | style?: StyleProp<TextStyle>;
|
| 46 | weight?: SymbolWeight;
|
| 47 | }) {
|
| 48 | return <MaterialIcons color={color} size={size} name={MAPPING[name]} style={style} />;
|
| 49 | }
|