Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change font family in React Navigation createStackNavigator

I use React Navigation as the navigator component of my app. I want to change font family of the stack navigator. Currently I do this to change the font family in iOS and it works pretty well:

const LoggedInStack = createStackNavigator({
  Home: {
    screen: Home,
    navigationOptions: {
      title: 'payX',
      headerTitleStyle: {
        fontFamily: "my-custom-font"
      }
    }
  }
});

but it doesn't work in Android devices. How should I change the code to make it work also in Android?

like image 641
Banafshe Alipour Avatar asked Sep 04 '18 06:09

Banafshe Alipour


People also ask

How do I change my font family in react?

To set a global font family in React, set the font-family style on the html element in your index. css file and import the file in your index. js file. Global CSS should be imported in index.

How do I change the heading font in react?

4 Answers. Show activity on this post. Add fontWeight: "200" to headerTitleStyle and it will work. const LoggedInStack = createStackNavigator({ Home: { screen: Home, navigationOptions: { title: 'payX', headerTitleStyle: { fontFamily: "my-custom-font", fontWeight: "200" } } } });

How do I change the font family in react material UI?

To change the font family of all React Material UI components, we can call the createTheme function provided by Material UI to set the font styles for the theme. Then we apply the theme with ThemeProvider to apply the styles to the whole app. We call createTheme with an object that has the typography.


2 Answers

Add fontWeight: "200" to headerTitleStyle and it will work.

const LoggedInStack = createStackNavigator({
  Home: {
    screen: Home,
    navigationOptions: {
      title: 'payX',
      headerTitleStyle: {
        fontFamily: "my-custom-font",
        fontWeight: "200"
      }
    }
  }
});

Default font weight is 500 and if it doesn't find a proper font with that weight, it will load default font instead.

like image 198
Aref Aslani Avatar answered Oct 14 '22 18:10

Aref Aslani


Thank you, i used it this way and it worked

const LoggedInStack = createStackNavigator({
   Home: { 
       screen: Home, 
       navigationOptions: { 
       headerTitle: <Text style={{ textAlign: 'center', flex: 1, fontFamily: 
        'my-custom-font'}}>payX</Text>  
       } 
   }
});
like image 37
Banafshe Alipour Avatar answered Oct 14 '22 17:10

Banafshe Alipour