Skip to content

fix(iOS): fix header back button display mode when back title text is custom #2860

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

Conversation

maciekstosio
Copy link
Contributor

@maciekstosio maciekstosio commented Apr 11, 2025

Description

Fixes #2809

⚠️ This change requires react-navigation changed to merged first and submodule bumped for test to pass.

This PR solves an issue, when using custom backTitle caused usage of the backButtonItem, which in turn disabled backButtonDisplayMode. This cause inconsistent behavior with UIKit - the back button label wasn't reduced to Back or chevron as it is does for backButtonDisplayMode.

Coresponding react-navigation changes.

Changes

  • Remove check if the backTitle is filled from condition that enforces backButtonItem usage and set backTitle by default.
  • Update docs
  • Update tests

Test code and steps to reproduce

see FabricExample/e2e/issuesTests/Test2809.e2e.ts and apps/src/tests/Test2809/index.tsx

Checklist

Copy link
Member

@kkafar kkafar left a comment

Choose a reason for hiding this comment

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

Nice, I have a small change request, though


// This has any effect only in case the `backBarButtonItem` is not set.
// We apply it before we configure the back item, because it might get overriden.
prevItem.backButtonDisplayMode = config.backButtonDisplayMode;
prevItem.backButtonTitle = resolvedBackTitle;
Copy link
Member

Choose a reason for hiding this comment

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

This looks ok, but the line 667 should be removed then, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed in: 383f254

@kkafar
Copy link
Member

kkafar commented Apr 11, 2025

If this is a fix, why do we have chore in PR title?

@maciekstosio maciekstosio changed the title chore(iOS): Fix header back button display mode when back title text is custom fix(iOS): fix header back button display mode when back title text is custom Apr 11, 2025
@maciekstosio
Copy link
Contributor Author

Test iOS e2e is failing due to the react-navigation not being updated. We want to merge this changes first, so I run tests locally:
image

@maciekstosio maciekstosio marked this pull request as ready for review April 11, 2025 11:31
@maciekstosio maciekstosio requested a review from kkafar April 11, 2025 11:35
Copy link
Member

@kkafar kkafar left a comment

Choose a reason for hiding this comment

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

Looks good now, thank you!

@kkafar
Copy link
Member

kkafar commented Apr 11, 2025

I'll merge this one, as I want to incorporate it into my changes.

@kkafar kkafar merged commit 0208e88 into main Apr 11, 2025
8 of 9 checks passed
@kkafar kkafar deleted the @maciekstosio/Fix-headerBackButtonDisplayMode-when-back-title-text-is-custom- branch April 11, 2025 12:49
maciekstosio added a commit to react-navigation/react-navigation that referenced this pull request Apr 11, 2025
**Motivation**

The iOS has a default behavior how to deal with back title label - it
changes its size depending on available space. It didn't work for custom
back title, as react-native-screens used custom back button item when
custom back title was provided. This changes in
software-mansion/react-native-screens#2860, thus
we can remove check on react-navigation side.

Corresponding docs update:
react-navigation/react-navigation.github.io#1422

**Test plan**

See `Test code and steps to reproduce` in
software-mansion/react-native-screens#2860 or
test this snippet (very long custom back button title should be changed
to `Back`):


<details>
<summary>Source code</summary>

```
import * as React from 'react';
import { Button, Text, View } from 'react-native';
import { ParamListBase } from '@react-navigation/native';
import {
  createNativeStackNavigator,
  NativeStackNavigationProp,
} from '@react-navigation/native-stack';


export function FinalScreen({
  navigation,
}: {
  navigation: NativeStackNavigationProp<ParamListBase>;
}) {
  return (
    <View style={{ flex: 1, backgroundColor: 'yellow', justifyContent: 'center', alignItems: 'center' }}>
      <Text>VOID</Text>
      <Button title="Pop to top" onPress={() => navigation.popTo('Home')} />
    </View>
  );
}

export function Home({
  navigation,
}: {
  navigation: NativeStackNavigationProp<ParamListBase>;
}) {
  return (
    <View style={{ flex: 1, backgroundColor: 'yellow' }}>
      <Button
        title="Open screen"
        onPress={() => navigation.navigate('Second')}
      />
    </View>
  );
}

export default () =>{
  const Stack = createNativeStackNavigator();

  return (
      <Stack.Navigator>
        <Stack.Screen name="First" component={Home} />
        <Stack.Screen name="Second" component={FinalScreen} options={{headerBackTitle: 'LongLongLongLongLong'}} />
      </Stack.Navigator>
  );
};

```
</details>

⚠️ Keep in mind that it requires changes from screens to work

---------

Co-authored-by: Kacper Kafara <kacperkafara@gmail.com>
maciekstosio added a commit that referenced this pull request Apr 11, 2025
## Description / Changes

bump react-navigation after changes from #2860

## Checklist

- [x] Ensured that CI passes
maciekstosio added a commit that referenced this pull request Apr 14, 2025
…#2867)

## Description / Changes

This is continuation of
#2860 that
proposes small refactor around back button logic. This area is very
confusing and in my opinion this is due to flag
`shouldUseCustomBackBarButtonItem` that breaks the flow of other if's
and causes other props to not work. Not we contained this flag in `if
(visible)` which currently is the only case when backButtonItem might be
used after the changes from #2800.

## Test code and steps to reproduce

see `FabricExample/e2e/issuesTests/Test2809.e2e.ts` and
`apps/src/tests/Test2809/index.tsx`

## Checklist
- [ ] Ensured that CI passes

---------

Co-authored-by: Kacper Kafara <kacperkafara@gmail.com>
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.

backButtonDisplayMode is not working when headerBackTitle is used
2 participants