-
-
Notifications
You must be signed in to change notification settings - Fork 561
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
fix(iOS): fix header back button display mode when back title text is custom #2860
Conversation
…@maciekstosio/Fix-headerBackButtonDisplayMode-when-back-title-text-is-custom-
…e-when-back-title-text-is-custom-
There was a problem hiding this 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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed in: 383f254
If this is a fix, why do we have |
There was a problem hiding this 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!
I'll merge this one, as I want to incorporate it into my changes. |
**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>
…#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>
Description
Fixes #2809
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
Test code and steps to reproduce
see
FabricExample/e2e/issuesTests/Test2809.e2e.ts
andapps/src/tests/Test2809/index.tsx
Checklist