Нет описания

icon-symbol.tsx 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Fallback for using MaterialIcons on Android and web.
  2. import MaterialIcons from '@expo/vector-icons/MaterialIcons';
  3. import { SymbolWeight, SymbolViewProps } from 'expo-symbols';
  4. import { ComponentProps } from 'react';
  5. import { OpaqueColorValue, type StyleProp, type TextStyle } from 'react-native';
  6. type IconMapping = Record<SymbolViewProps['name'], ComponentProps<typeof MaterialIcons>['name']>;
  7. type IconSymbolName = keyof typeof MAPPING;
  8. /**
  9. * Add your SF Symbols to Material Icons mappings here.
  10. * - see Material Icons in the [Icons Directory](https://icons.expo.fyi).
  11. * - see SF Symbols in the [SF Symbols](https://developer.apple.com/sf-symbols/) app.
  12. */
  13. const MAPPING = {
  14. 'house.fill': 'home',
  15. 'book.fill': 'menu-book',
  16. 'paperplane.fill': 'send',
  17. 'chevron.left.forwardslash.chevron.right': 'code',
  18. 'chevron.right': 'chevron-right',
  19. 'chevron.left': 'chevron-left',
  20. 'doc.text.image': 'description',
  21. 'bolt.circle.fill': 'flash-on',
  22. 'leaf.fill': 'eco',
  23. 'square.grid.2x2.fill': 'grid-view',
  24. 'leaf.circle.fill': 'eco',
  25. 'eye.fill': 'visibility',
  26. 'checklist': 'checklist',
  27. 'clock.fill': 'schedule',
  28. 'basket.fill': 'shopping-basket',
  29. 'cart.fill': 'shopping-cart',
  30. 'creditcard.fill': 'credit-card',
  31. 'map.fill': 'map',
  32. 'sparkles': 'auto-awesome',
  33. 'tray.full.fill': 'inventory',
  34. 'dollarsign.circle.fill': 'paid',
  35. 'person.crop.circle': 'person',
  36. 'plus.circle.fill': 'add-circle',
  37. 'photo.on.rectangle.angled': 'photo-library',
  38. 'photo': 'photo',
  39. } as IconMapping;
  40. /**
  41. * An icon component that uses native SF Symbols on iOS, and Material Icons on Android and web.
  42. * This ensures a consistent look across platforms, and optimal resource usage.
  43. * Icon `name`s are based on SF Symbols and require manual mapping to Material Icons.
  44. */
  45. export function IconSymbol({
  46. name,
  47. size = 24,
  48. color,
  49. style,
  50. }: {
  51. name: IconSymbolName;
  52. size?: number;
  53. color: string | OpaqueColorValue;
  54. style?: StyleProp<TextStyle>;
  55. weight?: SymbolWeight;
  56. }) {
  57. return <MaterialIcons color={color} size={size} name={MAPPING[name]} style={style} />;
  58. }