import React from 'react'; import { Image, I18nManager, ImageSourcePropType } from 'react-native'; import MaterialCommunityIcon, { accessibilityProps, } from './MaterialCommunityIcon'; import { withTheme } from '../../core/theming'; import { isImageSource } from './utils'; import type { Theme } from '../../types'; type IconSourceBase = string | ImageSourcePropType; export type IconSource = | IconSourceBase | Readonly<{ source: IconSourceBase; direction: 'rtl' | 'ltr' | 'auto' }> | ((props: IconProps & { color: string }) => React.ReactNode); type IconProps = { size: number; allowFontScaling?: boolean; }; type Props = IconProps & { color?: string; source: any; theme: Theme; }; const Icon = ({ source, color, size, theme, ...rest }: Props) => { const direction = typeof source === 'object' && source.direction && source.source ? source.direction === 'auto' ? I18nManager.isRTL ? 'rtl' : 'ltr' : source.direction : null; const s = typeof source === 'object' && source.direction && source.source ? source.source : source; const iconColor = color || theme?.colors?.text; if (isImageSource(s)) { return ( ); } else if (typeof s === 'string') { return ( ); } else if (typeof s === 'function') { return s({ color: iconColor, size, direction }); } return null; }; export default withTheme(Icon);