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

Issue mozilla-mobile#20637 - Fixed bug causing the tabs tray to scroll to the wrong tab when opened #21218

Merged
merged 2 commits into from
Sep 9, 2021
Merged

Conversation

MozillaNoah
Copy link
Contributor

@MozillaNoah MozillaNoah commented Sep 9, 2021

Fixes #20637

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.

To download an APK when reviewing a PR:

  1. click on Show All Checks,
  2. click Details next to "Taskcluster (pull_request)" after it appears and then finishes with a green checkmark,
  3. click on the "Fenix - assemble" task, then click "Run Artifacts".
  4. the APK links should be on the left side of the screen, named for each CPU architecture

@MozillaNoah MozillaNoah added the needs:review PRs that need to be reviewed label Sep 9, 2021
@MozillaNoah MozillaNoah requested review from a team as code owners September 9, 2021 17:20
@MozillaNoah MozillaNoah self-assigned this Sep 9, 2021
/**
* The maximum time from when a tab was created or accessed until it is considered "inactive".
*/
val maxActiveTime = TimeUnit.DAYS.toMillis(DEFAULT_ACTIVE_DAYS)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just wasn't sure where to refactor/relocate this to

Copy link
Contributor

Choose a reason for hiding this comment

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

For now, this is fine. I think we need to eventually move it somewhere else when the next set of settings land.

@@ -53,7 +55,7 @@ class TrayPagerAdapter(
itemView,
store,
interactor,
browserStore.state.normalTabs.indexOf(selectedTab)
browserStore.state.normalTabs.filter { it.isNormalTabActive(maxActiveTime) }.indexOf(selectedTab)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we have a single RecyclerView with multiple adapters, our "index" calculation is going to be a bit complicated.

From our last meeting, we need to scroll to the selected tab even if it's in the inactive tab section as well.

So we would need to do something like:

  1. Iterate through all adapters
  2. Find the adapter with a tab of the matching ID and viewholder type.
  3. Convert the relative adapter positive to the final adapter position.
  4. Tell the RV to scroll to this new position (because we need to say RecyclerView.scrollToPosition and there is no RecyclerView.Adapter.scrollToPosition).

This will also aid in solving a scrolling regression when we land other adapters like in 21177.

Copy link
Contributor

Choose a reason for hiding this comment

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

Spoke offline with Noah, we'll land this change for now and fix the scrolling problem when we land 21177 as well.

@@ -53,7 +55,7 @@ class TrayPagerAdapter(
itemView,
store,
interactor,
browserStore.state.normalTabs.indexOf(selectedTab)
browserStore.state.normalTabs.filter { it.isNormalTabActive(maxActiveTime) }.indexOf(selectedTab)
Copy link
Contributor

Choose a reason for hiding this comment

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

Spoke offline with Noah, we'll land this change for now and fix the scrolling problem when we land 21177 as well.

@MozillaNoah MozillaNoah added pr:needs-landing PRs that are ready to land [Will be merged by Mergify] and removed needs:review PRs that need to be reviewed labels Sep 9, 2021
@mergify mergify bot merged commit b3a86e9 into mozilla-mobile:main Sep 9, 2021
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]: Opening the tabs tray scrolls to the wrong position when inactive tabs are present
2 participants