import { Platform } from 'react-native'; export const isImageSource = (source: any) => // source is an object with uri (typeof source === 'object' && source !== null && Object.prototype.hasOwnProperty.call(source, 'uri') && typeof source.uri === 'string') || // source is a module, e.g. - require('image') typeof source === 'number' || // image url on web (Platform.OS === 'web' && typeof source === 'string' && (source.startsWith('data:image') || /\.(bmp|jpg|jpeg|png|gif|svg)$/.test(source))); export const getIconId = (source: any) => { if ( typeof source === 'object' && source !== null && Object.prototype.hasOwnProperty.call(source, 'uri') && typeof source.uri === 'string' ) { return source.uri; } return source; }; export const isValidIcon = (source: any) => typeof source === 'string' || typeof source === 'function' || isImageSource(source); export const isEqualIcon = (a: any, b: any) => a === b || getIconId(a) === getIconId(b);