Issue #18535: Do not animate first scroll to position

This looks less that ideal with a grid layout that swings by from the
normal tabs to private tabs.
upstream-sync
Jonathan Almeida 3 years ago committed by Jonathan Almeida
parent 8ccc4648a9
commit 2c6395cafe

@ -57,8 +57,19 @@ class TabLayoutMediator(
internal class TabLayoutObserver(
private val interactor: TabsTrayInteractor
) : TabLayout.OnTabSelectedListener {
private var initialScroll = true
override fun onTabSelected(tab: TabLayout.Tab) {
interactor.setCurrentTrayPosition(tab.position)
// Do not animate the initial scroll when opening the tabs tray.
val animate = if (initialScroll) {
initialScroll = false
false
} else {
true
}
interactor.setCurrentTrayPosition(tab.position, animate)
}
override fun onTabUnselected(tab: TabLayout.Tab) = Unit

@ -104,8 +104,8 @@ class TabsTrayFragment : AppCompatDialogFragment(), TabsTrayInteractor {
}
}
override fun setCurrentTrayPosition(position: Int) {
tabsTray.currentItem = position
override fun setCurrentTrayPosition(position: Int, smoothScroll: Boolean) {
tabsTray.setCurrentItem(position, smoothScroll)
}
override fun navigateToBrowser() {

@ -7,8 +7,11 @@ package org.mozilla.fenix.tabstray
interface TabsTrayInteractor {
/**
* Set the current tray item to the clamped [position].
*
* @param position The position on the tray to focus.
* @param smoothScroll If true, animate the scrolling from the current tab to [position].
*/
fun setCurrentTrayPosition(position: Int)
fun setCurrentTrayPosition(position: Int, smoothScroll: Boolean)
/**
* Dismisses the tabs tray and navigates to the browser.

@ -21,6 +21,21 @@ class TabLayoutObserverTest {
observer.onTabSelected(tab)
verify { interactor.setCurrentTrayPosition(1) }
verify { interactor.setCurrentTrayPosition(1, false) }
}
@Test
fun `WHEN observer is first started THEN do not smooth scroll`() {
val observer = TabLayoutObserver(interactor)
val tab = mockk<TabLayout.Tab>()
every { tab.position } returns 1
observer.onTabSelected(tab)
verify { interactor.setCurrentTrayPosition(1, false) }
observer.onTabSelected(tab)
verify { interactor.setCurrentTrayPosition(1, true) }
}
}

Loading…
Cancel
Save