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

Add headerLayoutPreset option to stack #4588

Merged
merged 1 commit into from
Jul 20, 2018

Conversation

brentvatne
Copy link
Member

@brentvatne brentvatne commented Jun 28, 2018

Motivation

#4092

  • headerLayoutPreset: 'center' | 'left' to provide an easy solution for questions like this.
  • headerBackTitleEnabled - this configuration option for stack navigator allows you to force back button titles to either be rendered or not (if you disagree with defaults for your platform and layout preset).
  • Also fixes Ripple back button Android is too wide #3955

@react-navigation-ci
Copy link

@react-navigation-ci
Copy link

@codecov-io
Copy link

codecov-io commented Jul 18, 2018

Codecov Report

Merging #4588 into master will decrease coverage by 0.16%.
The diff coverage is 62.74%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4588      +/-   ##
==========================================
- Coverage   67.92%   67.75%   -0.17%     
==========================================
  Files          57       57              
  Lines        1799     1833      +34     
==========================================
+ Hits         1222     1242      +20     
- Misses        577      591      +14
Impacted Files Coverage Δ
src/views/Header/HeaderTitle.js 100% <ø> (ø) ⬆️
src/views/StackView/StackViewLayout.js 36.04% <47.82%> (+1.01%) ⬆️
src/views/Header/Header.js 70.34% <70%> (+0.46%) ⬆️
src/views/Header/HeaderBackButton.js 69.23% <87.5%> (+2.56%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3c36db4...6b11f93. Read the comment docs.

@react-navigation-ci
Copy link

@react-navigation-ci
Copy link

…nd make it have reasonable defaults, better back button ripple on Android
@react-navigation-ci
Copy link

@brentvatne brentvatne merged commit cd3707d into master Jul 20, 2018
@react-navigation-ci
Copy link

@ahmetabdi
Copy link

@brentvatne Is this in 2.9.1? I have it in my stack navigator but it is not positioned to the left.

navigationOptions: () => ({
      headerTransparent: false,
      title: 'Settings',
      headerLeft: SettingsIcon,
      headerLayoutPreset: 'left',
}),

@brentvatne
Copy link
Member Author

it is not part of navigationOptions, you need to use it in the stack config

@ahmetabdi
Copy link

Oh thanks

@giantss
Copy link

giantss commented Dec 1, 2018

@brentvatne I always feel that the headerLayoutPreset configuration item should belong to navigationOptions.

@brentvatne
Copy link
Member Author

feel free to open a rfc to explain why you think that is the case: https://github.com/react-navigation/rfcs

@arsenalol69
Copy link

Can you updata Typescript definition ? Because TSLint can't find your new param :/

@brentvatne
Copy link
Member Author

@arsenalol69 #5276

@jcbertolucci
Copy link

it is not part of navigationOptions, you need to use it in the stack config

that saved my life

@danielsotopino
Copy link

@brentvatne I always feel that the headerLayoutPreset configuration item should belong to navigationOptions.

I feel the same

@react-navigation-ci
Copy link

react-navigation-ci commented Apr 25, 2019 via email

@danielsotopino
Copy link

I wouldn't be able to tell you how because i haven't read the code of react-navigation but the why is quite simple since many of the header styling can be done on navigationOptions.

I'll check the code later if i can, would be interesting to help on this.

@eleallegue
Copy link

I am dealing with the same problem and I feel same way. I think that in my case for example, I just want to have one header in the whole app and I want to center the name and so I have no header configuration anywhere. The only config of stack I have is the bottom navigation, so now I just cannot center the title unless I use a dirt solution that is leaving blank the headerLeft with a View component.

@esr360
Copy link

esr360 commented May 1, 2019

Don't know what an rfc is, but from a Developer Experience point of view, at least to me (as an inexperienced newbie), I agree it seems to make more sense for headerLayoutPreset to be part of navigationOptions.

@react-navigation-ci
Copy link

react-navigation-ci commented May 1, 2019 via email

@esr360
Copy link

esr360 commented May 1, 2019

For me it makes sense because I am calling navigationOptions on each screen, and have control of the navigation options wherever I am including the navigation. Setting the alignment of the navigation title seems like an option of the navigation rather than an option of the stack. I think it's feasible that different screens could potentially have different layout requirements.

As I'm a newbie, the only transitioning I've actually seen of screens is slide/fade animations so in that scenario at least it wouldn't have an impact.

can you explain why it makes sense for you and what you'd expect to see when transitioning when one screen in a stack has a certain header preset and the next screen has a different one?

On Wed, May 1, 2019 at 7:40 AM Edmund @.***> wrote: Don't know what an rfc is, but from a Developer Experience point of view, at least to me (as an inexperienced newbie), I agree it seems to make more sense for headerLayoutPreset to be part of navigationOptions. — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#4588 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/AIYL7TT4X4QEX4SJPNHUJNLPTGTUJANCNFSM4FHKHRYQ .

@enderandpeter
Copy link

Would someone mind taking a look at this again? From what I am seeing the headerLayoutPreset: 'center' stackConfig setting is not centering the header title on Android. I'm having to use a workaround instead.

@andywu0408
Copy link

andywu0408 commented Dec 7, 2019

const StackNavigator = createStackNavigator({
    screen: MyScreen,
    navigationOptions: {
        title: 'MyTitle'
    }
},
{
    headerLayoutPreset: 'center'
});

Adding it into stackConfig like this works for me, on both iOS and Android. Hope this helps!

@elie222
Copy link

elie222 commented Dec 29, 2019

Thanks @andywu0408. I ran into this issue myself recently. The issue is that it's not part of navigationOptions or defaultNavigationOptions. It works as in the Andy's example.

@radupm
Copy link

radupm commented May 21, 2020

Since React navigation 5 use headerTitleAlign:

defaultNavigationOptions: { title: 'Centered', headerTitleAlign: 'center' }

Defaults to center on iOS and left on Android.

@hadpro24
Copy link

hadpro24 commented Jun 6, 2020

You can go this link : https://reactnavigation.org/docs/stack-navigator/#headertitlealign

@marcvangend
Copy link

Documentation for version 6: https://reactnavigation.org/docs/elements/#headertitlealign

@github-actions
Copy link

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

Successfully merging this pull request may close these issues.

Ripple back button Android is too wide