Skip to content

Native Stack custom headerTitle doesn't support dynamic width content #2815

@santhosh-umapathi-wikifolio

Description

Description

Current behavior

The headerTitle component starts with a placeholder title (in this case just a dash):

Image

And when the actual title loads asynchronously, the width stays the same as when it only had the dash, cutting of the complete tilte (in this case the text "Header Title"):

Image

This happens when using either react native 0.77 or 0.78.

I'm only using a simple text as a custom headerTitle, but in my actual app I use a more complex header title structure with a title and a subtitle that has content which is loaded asynchronously and depends on a global context so it can't be solved by just using the children param received by the headerTitle.

Expected behavior

I'd expect that the width of the headerTitle is recalculated based on the component's width.

The title should go from the placeholder value ("-")

Image

To the new title loaded asynchronously ("Header Title") and let all the content be visible:

Image

I can fix this by passing the `Header` component from the `elements` library to the `header` option for the stack or for the screen, but it's no longer native and it has different styles like adding a bottom border, when the native one just has a bottom shadow.

Steps to reproduce

Open a Nested screen within stack navigator for the first time with Customer headerTitle

Snack or a link to a repository

https://github.com/DGVIP/react-navigation-header-title-issue

Screens version

4.10.0

React Native version

0.78.1

Platforms

iOS

JavaScript runtime

None

Workflow

None

Architecture

Fabric (New Architecture)

Build type

None

Device

iOS simulator

Device model

No response

Acknowledgements

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Missing infoThe user didn't precise the problem enoughMissing reproThis issue need minimum repro scenarioPlatform: iOSThis issue is specific to iOS

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions