React-native-ui-kitten: How to override default font

Created on 10 Nov 2019  路  11Comments  路  Source: akveo/react-native-ui-kitten

Issue type

I'm submitting a ... (check one with "x")

  • [ ] bug report
  • [x] feature request

Issue description

Current behavior:
I can't use a third font as a default font for UI Kitten.

Expected behavior:
I can use a third font as a default font for UI Kitten.

Help wanted Components

Most helpful comment

Hi! Currently, you can do this with custom mapping

import React from 'react';
import { mapping, light as theme } from '@eva-design/eva';
import { ApplicationProvider } from 'react-native-ui-kitten';

const strictTheme = { ['text-font-family']: 'OpenSans' }; // <-- Your Font
const customMapping = { strict: strictTheme };

const App = () => (
  <ApplicationProvider
    mapping={mapping}
    theme={theme}
    customMapping={customMapping}
  />
);

export default App;

All 11 comments

Hi! Currently, you can do this with custom mapping

import React from 'react';
import { mapping, light as theme } from '@eva-design/eva';
import { ApplicationProvider } from 'react-native-ui-kitten';

const strictTheme = { ['text-font-family']: 'OpenSans' }; // <-- Your Font
const customMapping = { strict: strictTheme };

const App = () => (
  <ApplicationProvider
    mapping={mapping}
    theme={theme}
    customMapping={customMapping}
  />
);

export default App;

Thanks 馃檹 @artyorsh .

Hey @artyorsh, I tried your solution but this only applies for <Text category='p1' />, another component has text not applied. How to resolve for this case?

import React from 'react';
import { mapping, light as theme } from '@eva-design/eva';
import { ApplicationProvider } from 'react-native-ui-kitten';

const customMapping = {
  ...mapping,
  strict: {
    ...mapping.strict,
    'text-font-family': 'dosis-regular'
  }
};

const App = () => (
  <ApplicationProvider
    mapping={customMapping}
    theme={theme}
  />
);

export default App;

@cuongw just follow my code. You do not need to merge it with default mapping since this will be done by UI Kitten

@artyorsh you have a little typo in your snippet:

const customMapping = { strict: scrictTheme };

should be

const customMapping = { strict: strictTheme };

Hello,

What about use different font weight?

this is my custom-mapping.json

{ "strict": { "text-font-family": "Montserrat" } }

Then in my App.js
await Font.loadAsync({ Montserrat: require('./assets/fonts/Montserrat-Medium.ttf') })

But all my <Text> elements show with Montserrat-Medium.ttf font.

How can I set up different weights?

Thank you

@jgutierro shows medium because you load medium? 馃What do you expect?

@artyorsh as I said in my last question: How can I set up different weights?

For example I would like to show a bold version of Montserrat all over <Text category='label'>

You may use custom mapping and add fontFamily for each category variant.
See the original implementation here

Thank you so much Artur!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nonameolsson picture nonameolsson  路  3Comments

evangunawan picture evangunawan  路  3Comments

gimli01 picture gimli01  路  3Comments

jeloagnasin picture jeloagnasin  路  3Comments

sarmadkung picture sarmadkung  路  3Comments