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.
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): restore native behavior of auto shortening back button title #2105
fix(iOS): restore native behavior of auto shortening back button title #2105
Changes from 1 commit
ee3ad3b
07c7e1e
4272ec4
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Why do we need to check the font family here?
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.
It's because due to the current implementation of
@react-navigation/native-stack
,backTitleFontFamily
will always be assigned to the font family offonts.regular
, which will be "System" if the default theme is used.It seems that the "System" font family is already the default on iOS, as setting the font family to "System" does not change the appearance, but in this case, will make
config.backTitleFontFamily
always resolve toYES
.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.
I see. Do you know, if we could rely on the native component that represents the title of back button, instead of comparing
config.backTitleFontFamily
?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.
Thanks for the PR, this is great!
Can we have this comment in the code please? @zetavg
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.
Thanks for the comment @tboba, but I'm sorry that due to my limited knowledge, I can't quite understand what you mean. Do you suggest we can handle this in something like the getter/setter of
RNSScreenStackHeaderConfig
, or the JS code inreact-navigation
?@kkafar Sure, I'll add comments to explain this besides related code once we finalize the solution.
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.
@zetavg I'm wondering if it would be possible to get title component of back title and check if it has default font set, but after further reflections I'm afraid this could lead to some flickers (setting the font and other properties -> checking the font of the native component -> setting system back 😄), so I guess we can stay with the current solution.
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.
Thanks for explaining, I think I got your point! I do think the current solution of comparing the font against
"System"
isn't perfect, one way is that there may be different ways to use the same system font (maybe".AppleSystemUIFont"
? I'm not sure), and ifreact-navigation
changes to also assign a default value toconfig.backTitleFontSize
this will break again.Your solution inspired me to think of a possible way to get this native behavior to work while still customizing the back button (such as changing the font or customizing the shortened "Back" text) - measure the width of the
headerTitle
andheaderRight
to see if there's enough space on layout, and replace thebackButtonTitle
with the shortened text or hide it. Well, flickering may be a problem.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.
Hi @zetavg, I know that this PR is already merged, but I wonder why do you set
isBackButtonCustomized
totrue
here. My understanding is that this else block is for the case when we hide back button, but want to preserve it in back menu. So, by default when we have navigationItem hidden we don't display anything here - nothing is customized, when we want to custom hide it from back manu then we setconfig.disableBackButtonMenu
which is in initial condition anyway.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.
Quick reply - I think it's because this
isBackButtonCustomized
is used to determine whether we need to assign thebackBarButtonItem
toprevItem.backBarButtonItem
later on line 556.Since
backBarButtonItem
has been changed here ([backBarButtonItem setTitle:nil];
), my understanding is that the changedbackBarButtonItem
has to be assigned toprevItem.backBarButtonItem
for the changes to take effect. So it should be considered customized - or changed. Maybe it's better to renameisBackButtonCustomized
toisBackBarButtonItemChanged
so that it will be more clear (or use another way to track if we have changed anything on backBarButtonItem).My guess is that if we do not set
isBackButtonCustomized
to true here, the back title won't be hidden as expected. I may need to verify it though.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.
Oh, I see that you had already done this in #2123. 🎉