Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the default font family of the entire react native app

Tags:

react-native

I need to add a custom font to my app. And all the text, including the button title, have to be displayed in the custom font. How can I achieve this?

I have added custom font in my app. But it needs to provide font family style to every text and can't change the font family of the button title.

like image 253
AKHIL Avatar asked Mar 04 '23 00:03

AKHIL


1 Answers

These answers seem like they didn't really read your question.. So here's how to use a font globally without the need of specifying it each and every time:

Create a component like so:

import * as React from 'react';
import { Text } from 'react-native';


export default (props) => {
  const defaultStyle = { fontFamily: 'Muli', color: '#14181c' };
  const incomingStyle = Array.isArray(props.style) ? props.style : [props.style];
  return <Text {...props} style={[defaultStyle, ...incomingStyle]} />;
};

Now, everywhere you have

import { Text } from 'react-native',

replace with

import { Text } from 'src/global-components' :)

like image 92
iuliu.net Avatar answered May 23 '23 04:05

iuliu.net