Nativebase: How to use custom fonts?

Created on 17 Dec 2016  路  7Comments  路  Source: GeekyAnts/NativeBase

Hi,
I have made a iconfont use createIconSet of react-native-vector-icons,and I don't known how to use it in NativeBase,Is there any speciel ways?

All 7 comments

We have conditionals for iconFamily hardcoded in this file

If you have created your own iconSet then you should create a fork of NativeBase and add your iconSet conditional in that file.

it would be nice if this information is somewhere more accessible, the link in this answer is broken. I know it's a year old question, just seems to come up a lot and no clear solution when searching this repo.

Hello,

in v2 if you want to add a custom font, you need to adapt the file IconNB.js. I did it this way with a font created from Icomoon and native-base 2.3.1:

native-base/dist/src/basic/IconNB.js :

import {MyIcons} from 'relative/path/to/MyFont';
[...]
var _MyIcons=MyIcons;var _MyIcons2=_interopRequireDefault(_MyIcons);
[...]
case"MyCustomFont":
this.Icon=_MyIcons2.default;
break;

MyFont.js :

import { createIconSetFromIcoMoon } from 'react-native-vector-icons';
import icoMoonConfig from 'MyFont.json';
const MyIcons = createIconSetFromIcoMoon(icoMoonConfig, 'icomoon', 'MyFont.ttf');
export { MyIcons }

In your component :

import {getTheme, StyleProvider, Icon} from 'native-base';
[...]
<StyleProvider style={getTheme({iconFamily : 'MyCustomFont'})}><Icon name="MyIconName"/></StyleProvider>

Cheers

How can you override the color of the Icon when you are using a StyleProvider??.

this wont work:
<Icon name="MyIconName" color="#f0ad4e"/>

Nevermind I found the answer:

<Icon name="MyIconName" style={{color:'#f0ad4e'}}/>

image

This is documented here https://docs.nativebase.io/Components.html#icon-def-headref

Thank you. But my issue was that the property color wasn't working when applying a StyleProvider.

To be clear:

This doesn't work
<StyleProvider style={getTheme({iconFamily : 'MyCustomFont'})}>
<Icon name="MyIconName" color="#fff"/>
</StyleProvider>

This works fine
<StyleProvider style={getTheme({iconFamily : 'MyCustomFont'})}>
<Icon name="MyIconName" style={{color:'#fff'}}/>
</StyleProvider>

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sihemhssine picture sihemhssine  路  3Comments

natashache picture natashache  路  3Comments

mcpracht picture mcpracht  路  3Comments

eggybot picture eggybot  路  3Comments

muthuraman007 picture muthuraman007  路  3Comments