For #7356: Scroll to selected tab when pressing tab overview
parent
414e905b76
commit
e8ad2389ac
|
@ -302,14 +302,10 @@ class DefaultBrowserToolbarController(
|
||||||
// Delay for a short amount of time so the browser has time to start animating out
|
// Delay for a short amount of time so the browser has time to start animating out
|
||||||
// before we transition the fragment. This makes the animation feel smoother
|
// before we transition the fragment. This makes the animation feel smoother
|
||||||
delay(ANIMATION_DELAY)
|
delay(ANIMATION_DELAY)
|
||||||
if (!navController.popBackStack(R.id.homeFragment, false)) {
|
val directions = BrowserFragmentDirections.actionBrowserFragmentToHomeFragmentPopUp(
|
||||||
val directions = BrowserFragmentDirections.actionBrowserFragmentToHomeFragment()
|
shouldScrollToSelectedTab = true
|
||||||
navController.nav(
|
|
||||||
R.id.browserFragment,
|
|
||||||
directions,
|
|
||||||
null
|
|
||||||
)
|
)
|
||||||
}
|
navController.navigate(directions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ import androidx.lifecycle.OnLifecycleEvent
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
|
import androidx.navigation.fragment.navArgs
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE
|
import androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE
|
||||||
|
@ -91,7 +92,9 @@ import org.mozilla.fenix.ext.requireComponents
|
||||||
import org.mozilla.fenix.ext.sessionsOfType
|
import org.mozilla.fenix.ext.sessionsOfType
|
||||||
import org.mozilla.fenix.ext.settings
|
import org.mozilla.fenix.ext.settings
|
||||||
import org.mozilla.fenix.ext.toTab
|
import org.mozilla.fenix.ext.toTab
|
||||||
|
import org.mozilla.fenix.home.sessioncontrol.AdapterItem
|
||||||
import org.mozilla.fenix.home.sessioncontrol.DefaultSessionControlController
|
import org.mozilla.fenix.home.sessioncontrol.DefaultSessionControlController
|
||||||
|
import org.mozilla.fenix.home.sessioncontrol.SessionControlAdapter
|
||||||
import org.mozilla.fenix.home.sessioncontrol.SessionControlInteractor
|
import org.mozilla.fenix.home.sessioncontrol.SessionControlInteractor
|
||||||
import org.mozilla.fenix.home.sessioncontrol.SessionControlView
|
import org.mozilla.fenix.home.sessioncontrol.SessionControlView
|
||||||
import org.mozilla.fenix.home.sessioncontrol.viewholders.CollectionViewHolder
|
import org.mozilla.fenix.home.sessioncontrol.viewholders.CollectionViewHolder
|
||||||
|
@ -502,6 +505,11 @@ class HomeFragment : Fragment() {
|
||||||
activity?.window?.setBackgroundDrawableResource(R.drawable.private_home_background_gradient)
|
activity?.window?.setBackgroundDrawableResource(R.drawable.private_home_background_gradient)
|
||||||
}
|
}
|
||||||
hideToolbar()
|
hideToolbar()
|
||||||
|
val safeArguments = arguments?.let { navArgs<HomeFragmentArgs>().value }
|
||||||
|
val shouldScrollToSelectedTab = safeArguments?.shouldScrollToSelectedTab ?: false
|
||||||
|
if (shouldScrollToSelectedTab) {
|
||||||
|
scrollToSelectedTab()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
|
@ -924,6 +932,17 @@ class HomeFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun scrollToSelectedTab() {
|
||||||
|
val position = (sessionControlView!!.view.adapter as SessionControlAdapter)
|
||||||
|
.currentList.indexOfFirst {
|
||||||
|
it is AdapterItem.TabItem && it.tab.selected == true
|
||||||
|
}
|
||||||
|
if (position > 0) {
|
||||||
|
(sessionControlView!!.view.layoutManager as LinearLayoutManager)
|
||||||
|
.scrollToPositionWithOffset(position, SELECTED_TAB_OFFSET)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val ANIMATION_DELAY = 100L
|
private const val ANIMATION_DELAY = 100L
|
||||||
|
|
||||||
|
@ -934,6 +953,7 @@ class HomeFragment : Fragment() {
|
||||||
private const val ANIM_SNACKBAR_DELAY = 100L
|
private const val ANIM_SNACKBAR_DELAY = 100L
|
||||||
private const val CFR_WIDTH_DIVIDER = 1.7
|
private const val CFR_WIDTH_DIVIDER = 1.7
|
||||||
private const val CFR_Y_OFFSET = -20
|
private const val CFR_Y_OFFSET = -20
|
||||||
|
private const val SELECTED_TAB_OFFSET = 20
|
||||||
|
|
||||||
// Layout
|
// Layout
|
||||||
private const val HEADER_MARGIN = 60
|
private const val HEADER_MARGIN = 60
|
||||||
|
|
|
@ -63,6 +63,10 @@
|
||||||
android:id="@+id/homeFragment"
|
android:id="@+id/homeFragment"
|
||||||
android:name="org.mozilla.fenix.home.HomeFragment"
|
android:name="org.mozilla.fenix.home.HomeFragment"
|
||||||
tools:layout="@layout/fragment_home">
|
tools:layout="@layout/fragment_home">
|
||||||
|
<argument
|
||||||
|
android:name="shouldScrollToSelectedTab"
|
||||||
|
app:argType="boolean"
|
||||||
|
android:defaultValue="false" />
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_homeFragment_to_turnOnSyncFragment"
|
android:id="@+id/action_homeFragment_to_turnOnSyncFragment"
|
||||||
app:destination="@+id/turnOnSyncFragment" />
|
app:destination="@+id/turnOnSyncFragment" />
|
||||||
|
@ -181,8 +185,9 @@
|
||||||
app:exitAnim="@anim/fade_out"
|
app:exitAnim="@anim/fade_out"
|
||||||
tools:layout="@layout/fragment_browser">
|
tools:layout="@layout/fragment_browser">
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_browserFragment_to_homeFragment"
|
android:id="@+id/action_browserFragment_to_homeFragment_popUp"
|
||||||
app:destination="@id/homeFragment" />
|
app:destination="@id/homeFragment"
|
||||||
|
app:popUpTo="@id/homeFragment" />
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_browserFragment_to_searchFragment"
|
android:id="@+id/action_browserFragment_to_searchFragment"
|
||||||
app:enterAnim="@anim/fade_in_up"
|
app:enterAnim="@anim/fade_in_up"
|
||||||
|
|
Loading…
Reference in New Issue