Kamil P
Kamil P

Reputation: 784

Using custom fonts in react native with font family name instead of file name

Problem:

I have font separated to 2 files, like "XSansRegular.ttf" and "XSansBold.ttf", both has same font family, like "X Sans".

I have added it as assets.

But when I'm trying to use them with setting:

style={{
    fontFamily: "X Sans"
}}

it doesn't work. I need to use exact file name, like this:

style={{
    fontFamily: "XSansRegular"
}}

What I want to do:

Use it with font name, instead of file name

style={{
    fontFamily: "X Sans"
}}

with possibility to pass there props like bold

style={{
    fontFamily: "X Sans",
    fontWeight: 'bold'
}}

Upvotes: 0

Views: 968

Answers (1)

Shika
Shika

Reputation: 41

Do you have the linked font files ?

If your react-native version >= 0.70,Run npx react-native-asset to link font files and try again.

Upvotes: 1

Related Questions