mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-03 23:15:31 +00:00
For #10496 - Automatically scroll to the selected tab when you open the tab tray
This commit is contained in:
parent
507ccaec7e
commit
0566790257
@ -83,6 +83,7 @@ import org.mozilla.fenix.utils.RunWhenReadyQueue
|
||||
import mozilla.components.concept.tabstray.TabsTray
|
||||
import mozilla.components.browser.tabstray.TabsAdapter
|
||||
import mozilla.components.browser.tabstray.BrowserTabsTray
|
||||
import org.mozilla.fenix.tabtray.FenixTabsAdapter
|
||||
import org.mozilla.fenix.tabtray.TabTrayViewHolder
|
||||
|
||||
/**
|
||||
@ -223,18 +224,12 @@ open class HomeActivity : LocaleAwareAppCompatActivity() {
|
||||
}
|
||||
}.asView()
|
||||
TabsTray::class.java.name -> {
|
||||
val layout = LinearLayoutManager(context)
|
||||
layout.reverseLayout = true
|
||||
layout.stackFromEnd = true
|
||||
|
||||
val adapter = TabsAdapter { parentView, _ ->
|
||||
TabTrayViewHolder(
|
||||
LayoutInflater.from(this).inflate(
|
||||
R.layout.tab_tray_item,
|
||||
parentView,
|
||||
false)
|
||||
)
|
||||
val layout = LinearLayoutManager(context).apply {
|
||||
reverseLayout = true
|
||||
stackFromEnd = true
|
||||
}
|
||||
|
||||
val adapter = FenixTabsAdapter(context)
|
||||
val decoration = DividerItemDecoration(
|
||||
context,
|
||||
DividerItemDecoration.VERTICAL
|
||||
|
@ -0,0 +1,31 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.tabtray
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import mozilla.components.browser.tabstray.TabsAdapter
|
||||
import mozilla.components.concept.tabstray.Tabs
|
||||
import org.mozilla.fenix.R
|
||||
|
||||
class FenixTabsAdapter(
|
||||
context: Context
|
||||
) : TabsAdapter(
|
||||
viewHolderProvider = { parentView, _ ->
|
||||
TabTrayViewHolder(
|
||||
LayoutInflater.from(context).inflate(
|
||||
R.layout.tab_tray_item,
|
||||
parentView,
|
||||
false)
|
||||
)
|
||||
}
|
||||
) {
|
||||
var onTabsUpdated: (() -> Unit)? = null
|
||||
|
||||
override fun updateTabs(tabs: Tabs) {
|
||||
super.updateTabs(tabs)
|
||||
onTabsUpdated?.invoke()
|
||||
}
|
||||
}
|
@ -57,6 +57,8 @@ class TabTrayView(
|
||||
private var tabsFeature: TabsFeature
|
||||
private var tabTrayItemMenu: TabTrayItemMenu
|
||||
|
||||
private var hasLoaded = false
|
||||
|
||||
override val containerView: View?
|
||||
get() = container
|
||||
|
||||
@ -98,8 +100,24 @@ class TabTrayView(
|
||||
{ it.content.private == isPrivate },
|
||||
{ })
|
||||
|
||||
|
||||
val selectedBrowserTabIndex = if (isPrivate) {
|
||||
view.context.components.core.store.state.privateTabs
|
||||
} else {
|
||||
view.context.components.core.store.state.normalTabs
|
||||
}.indexOfFirst { it.id == view.context.components.core.store.state.selectedTabId }
|
||||
|
||||
|
||||
(view.tabsTray as? BrowserTabsTray)?.also { tray ->
|
||||
TabsTouchHelper(tray.tabsAdapter).attachToRecyclerView(tray)
|
||||
(tray.tabsAdapter as? FenixTabsAdapter)?.also { adapter ->
|
||||
adapter.onTabsUpdated = {
|
||||
if (!hasLoaded) {
|
||||
hasLoaded = true
|
||||
tray.layoutManager?.scrollToPosition(selectedBrowserTabIndex)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tabTrayItemMenu = TabTrayItemMenu(view.context, { view.tab_layout.selectedTabPosition == 0 }) {
|
||||
|
Loading…
Reference in New Issue
Block a user