Skip to content

Commit

Permalink
Add hasIcon static method API (#666)
Browse files Browse the repository at this point in the history
* Add hasIcon static method to Icon class

* FIx CI

* FIx code styles

* Avoiding creating new array

* Update readme
  • Loading branch information
timwangdev authored and oblador committed Apr 2, 2018
1 parent 91ea8e3 commit 70e32c3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ 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.

### 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
5 changes: 5 additions & 0 deletions lib/create-icon-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ export default function createIconSet(glyphMap, fontFamily, fontFile) {
return Promise.resolve();
}

function hasIcon(name) {
return Object.prototype.hasOwnProperty.call(glyphMap, name);
}

Icon.Button = createIconButtonComponent(Icon);
Icon.TabBarItem = createTabBarItemIOSComponent(
IconNamePropType,
Expand All @@ -171,6 +175,7 @@ export default function createIconSet(glyphMap, fontFamily, fontFile) {
);
Icon.getImageSource = getImageSource;
Icon.loadFont = loadFont;
Icon.hasIcon = hasIcon;

return Icon;
}

0 comments on commit 70e32c3

Please sign in to comment.