license import { IconPack , IconProvider , } from './type' ; function throwPackNotFoundError ( name ) { const docRoot = 'https://akveo.github.io/react-native-ui-kitten/docs' ; const message = [ `\nIcon: Icon Pack '${ name }' is not registered` , 'Using UI Kitten components is only possible with configuring ApplicationProvider.' , `📖 Documentation: ${ docRoot }/guides/setting-up-icons` , ] . join ( '\n' ) ; throw Error ( message ) ; } function throwIconNotFoundError ( name , pack ) { const docRoot = 'https://akveo.github.io/react-native-ui-kitten/docs' ; const message = [ `\nIcon: '${ name }' icon is not registered in pack '${ pack }'.` , 'Check icon name or consider switching icon pack.' , `📖 Documentation: ${ docRoot }/guides/setting-up-icons` , ] . join ( '\n' ) ; throw Error ( message ) ; } export interface RegisteredIcon < T > { name : string ; pack : string ; icon : IconProvider < T > ; } type IconProps = any ; /**
 * This service allows to register multiple icon packs to use them later within
 * `<Icon/>` component.
 */ class RegistryService { protected packs : Map < string , IconPack < IconProps > > = new Map ( ) ; protected defaultPack : string ; param { IconPack [ ] } packs public register < T > ( ... packs ) { packs . forEach ( ( pack ) => { this . registerIconPack ( pack ) ; } ) ; } param { string } name throws public setDefaultIconPack ( name ) { if ( ! this . packs . has ( name ) ) { throwPackNotFoundError ( name ) ; } this . defaultPack = name ; } param { string } name returns { IconPack } public getIconPack < T > ( name ) { return this . packs . get ( name ) ; } param { string } name param { string } pack throws returns { RegisteredIcon } public getIcon < T > ( name , pack ? ) { const iconsPack = pack ? this . getPackOrThrow ( pack ) : this . getDefaultPack ( ) ; return { name , pack : iconsPack . name , icon : this . getIconFromPack ( name , iconsPack ) , } ; } param { IconPack } pack protected registerIconPack < T > ( pack ) { this . packs . set ( pack . name , pack ) ; } protected getPackOrThrow < T > ( name ) { const pack = this . packs . get ( name ) ; if ( ! pack ) { throwPackNotFoundError ( name ) ; } return pack ; } protected getDefaultPack < T > ( ) { return this . getIconPack ( this . defaultPack ) ; } protected getIconFromPack < T > ( name , pack , shouldThrow = true ) { if ( shouldThrow && ! pack . icons [ name ] ) { throwIconNotFoundError ( name , pack . name ) ; } return pack . icons [ name ] ; } } export const IconRegistryService = new RegistryService ( ) ;