From 5190490f7ac91318a3fc037887a136306c1d9004 Mon Sep 17 00:00:00 2001 From: Ioannis Kokkinidis Date: Tue, 24 Jul 2018 01:26:45 -0700 Subject: [PATCH] Exposes advanced methods in Icon component. (#762) * Now exposing the glyph map with Icon.getRawGlyphMap * Now exposing font family with getFontFamily * Exposed Icon methods to README.md * Fix typo, formatting and add more methods to Static Methods --- README.md | 9 ++++++++- lib/create-icon-set.js | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9e00bab9e..8da0cfcc0 100644 --- a/README.md +++ b/README.md @@ -219,7 +219,14 @@ Any [Text property](http://facebook.github.io/react-native/docs/text.html) and t |**`name`**|What icon to show, see Icon Explorer app or one of the links above. |*None*| |**`color`**|Color of the icon. |*Inherited*| -You can use `Icon.hasIcon(name)` to check if the name is valid in current icon set. +### Static Methods + +| Prop | Description | +|---|---| +|**`getFontFamily`**|Returns the font family that is currently used to retrieve icons as text. Usage: `const fontFamily = Icon.getFontFamily()`| +|**`getImageSource`**|Returns a promise that resolving to the source of a bitmap version of the icon for use with `Image` component et al. Usage: `const source = await Icon.getImageSource(name, size, color)`| +|**`getRawGlyphMap`**|Returns the raw glyph map of the icon set. Usage: `const glyphMap = Icon.getRawGlyphMap()` | +|**`hasIcon`**|Checks if the name is valid in current icon set. Usage: `const isNameValid = Icon.hasIcon(name)`| ### Styling Since `Icon` builds on top of the `Text` component, most [style properties](http://facebook.github.io/react-native/docs/style.html) will work as expected, you might find it useful to play around with these: diff --git a/lib/create-icon-set.js b/lib/create-icon-set.js index ec362a17d..dab119614 100644 --- a/lib/create-icon-set.js +++ b/lib/create-icon-set.js @@ -156,6 +156,14 @@ export default function createIconSet( return Object.prototype.hasOwnProperty.call(glyphMap, name); } + function getRawGlyphMap() { + return glyphMap; + } + + function getFontFamily() { + return fontReference; + } + Icon.Button = createIconButtonComponent(Icon); Icon.TabBarItem = createTabBarItemIOSComponent( IconNamePropType, @@ -169,6 +177,8 @@ export default function createIconSet( Icon.getImageSource = getImageSource; Icon.loadFont = loadFont; Icon.hasIcon = hasIcon; + Icon.getRawGlyphMap = getRawGlyphMap; + Icon.getFontFamily = getFontFamily; return Icon; }