feat(iOS, Stack): update back button configuration logic to handle iOS 26 and fix other problems #3303
+547
−59
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes back button configuration logic to handle following problems:
react-native-screens
' behavior was different,minimal
display mode withdisableBackButtonMenu: true
did not work correctly (back button menu remained enabled) .The only case that won't be supported after this PR (but it also hasn't been supported prior to this PR) is
generic
display mode on iOS versions prior to 26 whenbackTitleFontFamily
,backTitleFontSize
ordisableBackButtonMenu
is set. I decided that the appropriate approach is to fallback todefault
display mode behavior.Reasoning
Prior to this PR, there were many attempts to fix the back button configuration logic (e.g. #2800, #2860, #2867) but after native behavior change in iOS 26, I decided to have a look at this problem once again.
Here are the most important observations:
backButtonDisplayMode
property is ignored (what, to be fair, makes sense).backButtonTitle
property (or use custom back button).generic
back button text in custom back button (there is no API to get the localized string).Keeping those observations in mind, this is the configuration flow proposed in this PR:
Here is the comparison between prior and after this PR based on
Test2809
:Compatibility with previous versions
In order to maintain compatibility with previous
react-native-screens
andreact-navigation
versions, I addedbackButtonUseModernImplementation
prop.New
react-navigation
, newreact-native-screens
In new
react-navigation
release, we need to setbackButtonUseModernImplementation
totrue
and always passbackButtonDisplayMode
. Here is the patch toreact-navigation
:New version of
react-native-screens
will use new implementation only if it receivesbackButtonUseModernImplementation=true
. By default, the prop isfalse
.Old
react-navigation
, newreact-native-screens
No
backButtonUseModernImplementation
->backButtonUseModernImplementation=false
(default value) ->react-native-screens
uses legacy implementation, no changes to the back button logic.New
react-navigation
, oldreact-native-screens
react-native-screens
uses old implementation. PassingbackButtonDisplayMode
always directly, without the logic fromreact-navigation
to passundefined
in some cases will not change anything -undefined
was passed only when back button required customization. In such cases,backButtonDisplayMode
is ignored by the system already.Changes
backTitleVisible
backButtonUseNewImplementation
to switch between legacy and modern implementationsTest2809
Test code and steps to reproduce
Run
Test2809
. Please note the changes required toreact-navigation
to see new behavior.Checklist