Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Closes #28342: change the ui direction after a locale change #28343

Conversation

mavduevskiy
Copy link
Contributor

@mavduevskiy mavduevskiy commented Dec 29, 2022

FILE.2022-12-29.11.01.07.mp4

Pull Request checklist

  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Screenshots: This PR includes screenshots or GIFs of the changes made or an explanation of why it does not
  • Accessibility: The code in this PR follows accessibility best practices or does not include any user facing features. In addition, it includes a screenshot of a successful accessibility scan to ensure no new defects are added to the product.

QA

  • QA Needed

To download an APK when reviewing a PR (after all CI tasks finished running):

  1. Click on Checks at the top of the PR page.
  2. Click on the firefoxci-taskcluster group on the left to expand all tasks.
  3. Click on the build-debug task.
  4. Click on View task in Taskcluster in the new DETAILS section.
  5. The APK links should be on the right side of the screen, named for each CPU architecture.

GitHub Automation

Fixes #28342

@@ -229,6 +231,10 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {

components.publicSuffixList.prefetch()

// Changing a language on the Language screen restarts the activity, but the activity keeps
// the old layout direction. We have to update the direction manually.
window.decorView.layoutDirection = TextUtils.getLayoutDirectionFromLocale(Locale.getDefault())
Copy link
Contributor

Choose a reason for hiding this comment

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

Drive by: This seems like a last resort location to do an initialization step from a setting. Would it be possible to include this in the locale settings flow when updating the language? DefaultLocaleSettingsController might be a better alternative.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was my first though as well, but this approach has an issue – invalidating the layout and recreating the activity happens not synchronously and looks like a glitch.

FILE.2023-01-09.13.00.00.mp4

What concerned did you have in mind here? Applying proper orientation during onCreate looks okay to me. setLayoutDirection has also a safety check to invalidate the layout only if it is needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Where is the orientation being set in HomeActivity?

My primary concern is that this was even needed at all and might be a heavy hammer, but I did notice that HomeActivity extends from LocaleAwareAppCompatActivity which has this same line in its own onCreate. Based on the adjacent comment in HomeActivity, the super.onCreate only gets called after some disk read violations, but it was obviously needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The use-case I am working on is DefaultLocaleSettingsController changing the Locale to something that has a different text orientation and restarts the activity. Changing the locale should also change the layout orientation, but it doesn't and the activity is recreated with the old orientation. To avoid glitching, enforcing changed orientation looks like a good idea to me. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Judging by the conversation in #9413, I think I'm OK with this approach, as it's a natural side effect of us having to take care of all of the configuration changes. Maybe it won't be necessary in a 100% Compose world 🤞

@mavduevskiy
Copy link
Contributor Author

Thank you, Noah! @MozillaNoah

@mavduevskiy mavduevskiy added the pr:needs-landing PRs that are ready to land [Will be merged by Mergify] label Jan 20, 2023
@mergify mergify bot merged commit 26551b6 into mozilla-mobile:main Jan 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr:needs-landing PRs that are ready to land [Will be merged by Mergify]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] change RTL/LTR languages doesn't update the UI until new launch
2 participants