-
-
Notifications
You must be signed in to change notification settings - Fork 598
fix(iOS): restore native behavior of auto shortening back button title #2105
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -511,8 +511,13 @@ + (void)updateViewController:(UIViewController *)vc | |
| action:nil]; | ||
| [backBarButtonItem setMenuHidden:config.disableBackButtonMenu]; | ||
|
|
||
| auto isBackButtonCustomized = !isBackTitleBlank || config.disableBackButtonMenu || NO; | ||
|
|
||
| if (config.isBackTitleVisible) { | ||
| if (config.backTitleFontFamily || config.backTitleFontSize) { | ||
| if ((config.backTitleFontFamily && | ||
| ![config.backTitleFontFamily isEqual:@"System"]) || | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to check the font family here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's because due to the current implementation of 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 @kkafar Sure, I'll add comments to explain this besides related code once we finalize the solution.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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 |
||
| config.backTitleFontSize) { | ||
| isBackButtonCustomized = YES; | ||
| NSMutableDictionary *attrs = [NSMutableDictionary new]; | ||
| NSNumber *size = config.backTitleFontSize ?: @17; | ||
| if (config.backTitleFontFamily) { | ||
|
|
@@ -535,9 +540,17 @@ + (void)updateViewController:(UIViewController *)vc | |
| // When backBarButtonItem's title is null, back menu will use value | ||
| // of backButtonTitle | ||
| [backBarButtonItem setTitle:nil]; | ||
| isBackButtonCustomized = YES; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quick reply - I think it's because this Since My guess is that if we do not set
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Oh, I see that you had already done this in #2123. 🎉 |
||
| prevItem.backButtonTitle = resolvedBackTitle; | ||
| } | ||
| prevItem.backBarButtonItem = backBarButtonItem; | ||
|
|
||
| // Prevent unnecessary assignment of backBarButtonItem if it is not customized, | ||
| // as assigning one will override the native behavior of automatically shortening | ||
| // the title to "Back" or hide the back title if there's not enough space. | ||
| // See: https://github.com/software-mansion/react-native-screens/issues/1589 | ||
| if (isBackButtonCustomized) { | ||
| prevItem.backBarButtonItem = backBarButtonItem; | ||
| } | ||
|
|
||
| if (@available(iOS 11.0, *)) { | ||
| if (config.largeTitle) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.