38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
// Fallback for using MaterialIcons on Android and web.
|
|
|
|
import MaterialIcons from '@expo/vector-icons/MaterialIcons';
|
|
import { SymbolViewProps, SymbolWeight } from 'expo-symbols';
|
|
import { ComponentProps } from 'react';
|
|
import { OpaqueColorValue, type StyleProp, type TextStyle } from 'react-native';
|
|
|
|
const MAPPING = {
|
|
'house.fill': 'home',
|
|
'paperplane.fill': 'send',
|
|
'chevron.left.forwardslash.chevron.right': 'code',
|
|
'chevron.right': 'chevron-right',
|
|
'person.fill': 'person',
|
|
'map.fill': 'map',
|
|
'star.fill': 'star',
|
|
'clock.fill': 'access-time',
|
|
} as IconMapping;
|
|
|
|
/**
|
|
* An icon component that uses native SF Symbols on iOS, and Material Icons on Android and web.
|
|
* This ensures a consistent look across platforms, and optimal resource usage.
|
|
* Icon `name`s are based on SF Symbols and require manual mapping to Material Icons.
|
|
*/
|
|
export function IconSymbol({
|
|
name,
|
|
size = 24,
|
|
color,
|
|
style,
|
|
}: {
|
|
name: IconSymbolName;
|
|
size?: number;
|
|
color: string | OpaqueColorValue;
|
|
style?: StyleProp<TextStyle>;
|
|
weight?: SymbolWeight;
|
|
}) {
|
|
return <MaterialIcons color={color} size={size} name={MAPPING[name]} style={style} />;
|
|
}
|