From 70e32c3ce7fa22ff725355c79be71fec5a0dfc19 Mon Sep 17 00:00:00 2001 From: Tim Wang Date: Mon, 2 Apr 2018 21:37:33 +0800 Subject: [PATCH] Add hasIcon static method API (#666) * Add hasIcon static method to Icon class * FIx CI * FIx code styles * Avoiding creating new array * Update readme --- README.md | 2 ++ lib/create-icon-set.js | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/README.md b/README.md index 33ecfe965..f17c4b29c 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/lib/create-icon-set.js b/lib/create-icon-set.js index c8dd9239c..019313b9b 100644 --- a/lib/create-icon-set.js +++ b/lib/create-icon-set.js @@ -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, @@ -171,6 +175,7 @@ export default function createIconSet(glyphMap, fontFamily, fontFile) { ); Icon.getImageSource = getImageSource; Icon.loadFont = loadFont; + Icon.hasIcon = hasIcon; return Icon; }