Skip to content

Commit

Permalink
Exposes advanced methods in Icon component. (#762)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
SudoPlz authored and oblador committed Jul 24, 2018
1 parent cfb58ca commit 5190490
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions lib/create-icon-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}

0 comments on commit 5190490

Please sign in to comment.