Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposes advanced methods in Icon component. #762

Merged
merged 4 commits into from
Jul 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,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 @@ -163,6 +163,14 @@ export default function createIconSet(glyphMap, fontFamily, fontFile) {
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 @@ -176,6 +184,8 @@ export default function createIconSet(glyphMap, fontFamily, fontFile) {
Icon.getImageSource = getImageSource;
Icon.loadFont = loadFont;
Icon.hasIcon = hasIcon;
Icon.getRawGlyphMap = getRawGlyphMap;
Icon.getFontFamily = getFontFamily;

return Icon;
}