Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any way to change header's font ? #542

Closed
yeknava opened this issue Mar 2, 2017 · 27 comments
Closed

Is there any way to change header's font ? #542

yeknava opened this issue Mar 2, 2017 · 27 comments

Comments

@yeknava
Copy link

yeknava commented Mar 2, 2017

Is there any way to change header's font ?
i tried this but didn't work.

static navigationOptions = {
	    title: 'title',
	    header: {
	    	titleStyle: {
	    		fontFamily: 'test'
	    	}
	    }    
	}
@grabbou
Copy link

grabbou commented Mar 2, 2017

That's how it should work. Are you sure you don't override header config? Do you specify navigationOptions in any other places?

@yeknava
Copy link
Author

yeknava commented Mar 2, 2017

yes. there is not other options that override it. color and other styles, everything works but fontFamily.

@ghost
Copy link

ghost commented Mar 2, 2017

Make sure you're using a supported fontFamily I just tried one and it works.

Here's a list of supported fonts: https://github.com/dabit3/react-native-fonts

static navigationOptions = {
  header: ({ navigate }) => {
    return {
      titleStyle: {
        fontFamily: 'American Typewriter'
      },
    };
  },
};

@grabbou
Copy link

grabbou commented Mar 2, 2017

Since the title passes and the end component is <text />, I don't think it's an issue with React Navigation. Does that font work for other components within your app?

@thotegowda
Copy link

thotegowda commented Mar 2, 2017

I have also faced this problem. The main problem seems to be in react-native rather than react-navigation.

HeaderTitle.js sets fontWeight as fontWeight: Platform.OS === 'ios' ? '600' : '500',

When fontWeight is set to >=500, react-native expects bold variation of custom font (naming convention CustomFont_bold.ttf) to be present. If it fails find bold variation of custom font, it falls back to default font family instead of custom font family with regular font.

In this case, app is setting fontFamily to custom font and HeaderTitle.js is hardcoding fontWeight to 500, so custom font will never reflect.
Quick fix would be have fontWeight: "200" in your header.titleStyle of your navigationOptions. or keep bold variation of your custom font

I'm planning to raise PR in react-native project to fix it by falling back to regular variation of custom font instead default family bold font.

But if you feel, HeaderTitle.js should always read fontWeight from header.titleStyle. Let me know, happy to raise a PR.

@grabbou grabbou closed this as completed Mar 2, 2017
@allpwrfulroot
Copy link

Just to note, Exponent does not support fontWeight or fontStyle at the moment, so those of us with custom fonts are SOL at the moment unless we go in and change the src.

@kamalk333
Copy link

@thotegowda Heyy!!! thanks for that quick fix, that really helped me.

@airguide
Copy link

airguide commented May 2, 2017

headerTitle: <Text style={ styles.textHeader }>Dashboard</Text>
Works on android

@WilliamIPark
Copy link

Just because I landed here through a google search on how to change a headers font in general, and none of the above was working:

Use headerTitleStyle in navigationOptions.

@aroth
Copy link

aroth commented Sep 19, 2017

@thotegowda any further information on this? did you have a chance to submit a PR?

@anceque
Copy link

anceque commented Oct 2, 2017

@aroth Renaming the font to CustomFont_bold and using it with headerTitleStyle really does the magic. Try it.

@Charlynux
Copy link

If your fontFamily doesn't on Android for "headerTitleStyle" or "labelStyle", check weights managed by your font.

Just discover after some research that Android use a default font, if requested font doesn't have the requested fontWeight. (iOS seems to ignore fontWeight in this case.)
Both HeaderTitle and DrawerNavigatorItems define fontWeight (respectively 500 and bold).

My workaround is to define a font weight present in my TTF file in "headerTitleStyle" and "labelStyle".

labelStyle: {
  fontWeight: "normal",
  fontFamily: "Chalet-NewYorkNineteenSeventy"
}

Hope this could help someone.

@pallavbakshi
Copy link

pallavbakshi commented Jan 14, 2018

In Jan 2018,
` static navigationOptions = ({ navigation }) => ({

title: 'Projects',

headerTitleStyle: {

    fontWeight: '300',

    color: '#ffffff',

    fontFamily: 'Nunito-Regular',

    fontSize: 16
  }

})`

@mastersam92
Copy link

In feb 2018 :)

Not worked for me, but, solved( for me ):

-It is important, that 'fontFamily' contain name of font file( w/o extention )

In my case, name of font file: 'EuclidFlex-Regular.otf'
This font applying( android ) only when i set: fontFamily: 'EuclidFlex-Regular'
Whereas iOS works perfectly with real font name( i.e fontFamily: 'Euclid Flex' )

@Charlynux
Copy link

That's well explained in this article.
https://medium.com/react-native-training/react-native-custom-fonts-ccc9aacf9e5e

@yasir-netlinks
Copy link

Hi guys, I am looking for a way to make the title text bold when the tab is active! Any ideas, thanx

static navigationOptions = {
        title: 'Groups',  // how to set bold when active
        tabBarIcon: ({ focused }) => {
            let imageSource = focused
            ? require('../../../assets/iconGroupsSelected/iconGroupsSelected.png')
            : require('../../../assets/iconGroups/iconGroups.png')
            return <Image
                source={ imageSource }
            />
        },
    }

@mlazari
Copy link

mlazari commented Apr 23, 2018

@Charlynux Thank you for the hint. I was wondering why the font is working in other components, but not working in headerTitleStyle. I added fontWeight: undefined to headerTitleStyle and it's working now.

@ivanfranchi
Copy link

for One Plus 5t I got it working with
static navigationOptions = { title: 'Title', headerTitleStyle: { fontFamily: 'Roboto', } }
Default font was truncating no matter the length of the title text

@pascaloliv
Copy link

pascaloliv commented Nov 14, 2018

@Charlynux Thank you for the hint. I was wondering why the font is working in other components, but not working in headerTitleStyle. I added fontWeight: undefined to headerTitleStyle and it's working now.

⬆️ See above @mlazari answer ⬆️

This portion of code wasn't working. ❌

{
  color: 'white',
  fontFamily: 'Montserrat-Bold',
  fontSize: 16,
}

When I added fontWeight: undefined , it worked very well. ✅

{
  color: 'white',
  fontFamily: 'Montserrat-Bold',
  fontSize: 16,
+  fontWeight: undefined,
}

It looks like a bug, or at least a weird font behaviour.

@steniowagner
Copy link

Wow! That so weird...

fontWeight: undefined works like a charm!

Thank you @pascaloliv @Charlynux and @mlazari!

@Kalpeshsuthar
Copy link

@Charlynux Thank you for the hint. I was wondering why the font is working in other components, but not working in headerTitleStyle. I added fontWeight: undefined to headerTitleStyle and it's working now.

⬆️ See above @mlazari answer ⬆️

This portion of code wasn't working. ❌

{
  color: 'white',
  fontFamily: 'Montserrat-Bold',
  fontSize: 16,
}

When I added fontWeight: undefined , it worked very well. ✅

{
  color: 'white',
  fontFamily: 'Montserrat-Bold',
  fontSize: 16,
+  fontWeight: undefined,
}

It looks like a bug, or at least a weird font behaviour.

it's really working but really and surprised also that why font weight is required.

@mlazari
Copy link

mlazari commented Feb 1, 2019

@Kalpeshsuthar I guess it's what @thotegowda said above.

@kpratik2015
Copy link

I have also faced this problem. The main problem seems to be in react-native rather than react-navigation.

HeaderTitle.js sets fontWeight as fontWeight: Platform.OS === 'ios' ? '600' : '500',

When fontWeight is set to >=500, react-native expects bold variation of custom font (naming convention CustomFont_bold.ttf) to be present. If it fails find bold variation of custom font, it falls back to default font family instead of custom font family with regular font.

In this case, app is setting fontFamily to custom font and HeaderTitle.js is hardcoding fontWeight to 500, so custom font will never reflect.
Quick fix would be have fontWeight: "200" in your header.titleStyle of your navigationOptions. or keep bold variation of your custom font

I'm planning to raise PR in react-native project to fix it by falling back to regular variation of custom font instead default family bold font.

But if you feel, HeaderTitle.js should always read fontWeight from header.titleStyle. Let me know, happy to raise a PR.

Thanks man, you helped me

@ridmal
Copy link

ridmal commented Sep 30, 2019

@thotegowda Thanks , you saved me. :)

@SaphiraNgocThuy
Copy link

If your fontFamily doesn't on Android for "headerTitleStyle" or "labelStyle", check weights managed by your font.

Just discover after some research that Android use a default font, if requested font doesn't have the requested fontWeight. (iOS seems to ignore fontWeight in this case.)
Both HeaderTitle and DrawerNavigatorItems define fontWeight (respectively 500 and bold).

My workaround is to define a font weight present in my TTF file in "headerTitleStyle" and "labelStyle".

labelStyle: {
  fontWeight: "normal",
  fontFamily: "Chalet-NewYorkNineteenSeventy"
}

Hope this could help someone.

Cool!! Big thankssss!!

@RemyMachado
Copy link

Is there a way to change it for all headers once. Using the theme for instance? The documentation is really poor in this regard.

@github-actions
Copy link

github-actions bot commented Oct 5, 2021

Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests