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

fix: setting headerBackTitleVisible to false not working on iOS #11937

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zetavg
Copy link

@zetavg zetavg commented Apr 14, 2024

Motivation

According to the docs, setting headerBackTitleVisible to false should hide the back title on iOS, while this is not the case with react-native-screens v3.29+.

Cause

With the current code, backTitle={headerBackTitleVisible ? headerBackTitle : ' '}, the back title is set to a blank string if headerBackTitleVisible is false. However, in newer versions of react-native-screens, the backTitle will be considered blank if it only contains white spaces, making it fallback to the default title - which makes the back title not hidden at all.

Fix

Assign the backTitleVisible property of RNSScreenStackHeaderConfig native component, which seems to be a legit way to hide the back title.

Test plan

  1. Create a native stack navigator with the backTitleVisible screen option set to false.
  2. See if the back title is hidden on iOS when navigating to another screen.
Expected Not Expected
  • May need to test if assigning the new property will break older versions of react-native-screens.
    • Tested with react-native-screens 3.20.0 and 3.21.0, app does not crash and the back title remains hidden-able.

Copy link

Hey @zetavg! Thanks for opening your first pull request in this repo. If you haven't already, make sure to read our contribution guidelines.

Copy link

netlify bot commented Apr 14, 2024

Deploy Preview for react-navigation-example ready!

Name Link
🔨 Latest commit de8fb84
🔍 Latest deploy log https://app.netlify.com/sites/react-navigation-example/deploys/661c1d9fe9eddf0008995cae
😎 Deploy Preview https://deploy-preview-11937--react-navigation-example.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@@ -182,6 +182,7 @@ export function HeaderConfig({
backButtonInCustomView={backButtonInCustomView}
backgroundColor={headerBackgroundColor}
backTitle={headerBackTitleVisible ? headerBackTitle : ' '}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we still consider headerBackTitleVisible in backTitle, if we're passing backTitleVisible below? I believe the button will be hidden anyway.

Copy link
Author

@zetavg zetavg Apr 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's necessary for people who are using older versions of react-native-screens, since backTitleVisible is introduced in react-native-screens 3.21.0 and @react-navigation/native-stack has peer dependency of react-native-screens as >= 3.0.0.

(However, I haven't tested if only setting backTitleVisible will actually not work with react-native-screens <3.21.0 for now.)

I may need to add a "for backward competitivity" comment for this.

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

Successfully merging this pull request may close these issues.

None yet

2 participants