import { createIconSet } from "react-native-vector-icons" ; import { ensure } from "@mendix/pluggable-widgets-tools" ; import { glyphMap } from "./Halflings" ; export const GlyphIcon = createIconSet ( glyphMap , "GLYPHICONS Halflings" , "glyphicons-halflings-regular.ttf" ) ; interface Icon { uri : string ; scale : number ; } interface ImageSourcesCache { [ iconClassName ] : Icon ; } export const getIcon = ( iconName ) : Promise < Icon > => GlyphIcon . getImageSource ( iconName , 20 , "black" ) ; export const preloadIcons = ( iconNames ) : Promise < ImageSourcesCache > => Promise . all ( iconNames . map ( iconName => getIcon ( iconName ) ) ) . then ( imageSources => iconNames . reduce ( buildImageCache ( imageSources ) , { } ) ) ; const buildImageCache = ( imageSources ) => ( imageSourcesCache , iconName , index ) => { imageSourcesCache [ iconName ] = ensure ( imageSources [ index ] ) ; return imageSourcesCache ; } ;