mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-17 15:26:23 +00:00
Bug 1822193 - Scroll to the active tab when opening the Tabs Tray
This commit is contained in:
parent
c9b5c9a7d4
commit
4e5757a0ac
@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
@ -145,7 +146,9 @@ fun TabsTray(
|
||||
) { position ->
|
||||
when (Page.positionToPage(position)) {
|
||||
Page.NormalTabs -> {
|
||||
val showInactiveTabsAutoCloseDialog = shouldShowInactiveTabsAutoCloseDialog(inactiveTabs.size)
|
||||
if (normalTabs.isNotEmpty() || inactiveTabs.isNotEmpty()) {
|
||||
val showInactiveTabsAutoCloseDialog =
|
||||
shouldShowInactiveTabsAutoCloseDialog(inactiveTabs.size)
|
||||
var showAutoCloseDialog by remember { mutableStateOf(showInactiveTabsAutoCloseDialog) }
|
||||
|
||||
val optionalInactiveTabsHeader: (@Composable () -> Unit)? = if (inactiveTabs.isEmpty()) {
|
||||
@ -187,8 +190,16 @@ fun TabsTray(
|
||||
onTabLongClick = onTabLongClick,
|
||||
header = optionalInactiveTabsHeader,
|
||||
)
|
||||
} else {
|
||||
Text(
|
||||
text = "Empty state",
|
||||
color = FirefoxTheme.colors.textPrimary,
|
||||
style = FirefoxTheme.typography.body1,
|
||||
)
|
||||
}
|
||||
}
|
||||
Page.PrivateTabs -> {
|
||||
if (privateTabs.isNotEmpty()) {
|
||||
TabLayout(
|
||||
tabs = privateTabs,
|
||||
displayTabsInGrid = displayTabsInGrid,
|
||||
@ -199,6 +210,13 @@ fun TabsTray(
|
||||
onTabClick = handleTabClick,
|
||||
onTabLongClick = onTabLongClick,
|
||||
)
|
||||
} else {
|
||||
Text(
|
||||
text = "Empty state",
|
||||
color = FirefoxTheme.colors.textPrimary,
|
||||
style = FirefoxTheme.typography.body1,
|
||||
)
|
||||
}
|
||||
}
|
||||
Page.SyncedTabs -> {
|
||||
val syncedTabs = tabsTrayStore
|
||||
|
@ -59,10 +59,20 @@ fun TabLayout(
|
||||
onTabLongClick: (TabSessionState) -> Unit,
|
||||
header: (@Composable () -> Unit)? = null,
|
||||
) {
|
||||
var selectedTabIndex = 0
|
||||
selectedTabId?.let {
|
||||
tabs.forEachIndexed { index, tab ->
|
||||
if (tab.id == selectedTabId) {
|
||||
selectedTabIndex = index
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (displayTabsInGrid) {
|
||||
TabGrid(
|
||||
tabs = tabs,
|
||||
selectedTabId = selectedTabId,
|
||||
selectedTabIndex = selectedTabIndex,
|
||||
selectionMode = selectionMode,
|
||||
onTabClose = onTabClose,
|
||||
onTabMediaClick = onTabMediaClick,
|
||||
@ -74,6 +84,7 @@ fun TabLayout(
|
||||
TabList(
|
||||
tabs = tabs,
|
||||
selectedTabId = selectedTabId,
|
||||
selectedTabIndex = selectedTabIndex,
|
||||
selectionMode = selectionMode,
|
||||
onTabClose = onTabClose,
|
||||
onTabMediaClick = onTabMediaClick,
|
||||
@ -89,6 +100,7 @@ fun TabLayout(
|
||||
private fun TabGrid(
|
||||
tabs: List<TabSessionState>,
|
||||
selectedTabId: String?,
|
||||
selectedTabIndex: Int,
|
||||
selectionMode: TabsTrayState.Mode,
|
||||
onTabClose: (TabSessionState) -> Unit,
|
||||
onTabMediaClick: (TabSessionState) -> Unit,
|
||||
@ -96,7 +108,7 @@ private fun TabGrid(
|
||||
onTabLongClick: (TabSessionState) -> Unit,
|
||||
header: (@Composable () -> Unit)? = null,
|
||||
) {
|
||||
val state = rememberLazyGridState()
|
||||
val state = rememberLazyGridState(initialFirstVisibleItemIndex = selectedTabIndex)
|
||||
val tabListBottomPadding = dimensionResource(id = R.dimen.tab_tray_list_bottom_padding)
|
||||
val isInMultiSelectMode = selectionMode is TabsTrayState.Mode.Select
|
||||
|
||||
@ -138,6 +150,7 @@ private fun TabGrid(
|
||||
private fun TabList(
|
||||
tabs: List<TabSessionState>,
|
||||
selectedTabId: String?,
|
||||
selectedTabIndex: Int,
|
||||
selectionMode: TabsTrayState.Mode,
|
||||
onTabClose: (TabSessionState) -> Unit,
|
||||
onTabMediaClick: (TabSessionState) -> Unit,
|
||||
@ -145,7 +158,7 @@ private fun TabList(
|
||||
onTabLongClick: (TabSessionState) -> Unit,
|
||||
header: (@Composable () -> Unit)? = null,
|
||||
) {
|
||||
val state = rememberLazyListState()
|
||||
val state = rememberLazyListState(initialFirstVisibleItemIndex = selectedTabIndex)
|
||||
val tabListBottomPadding = dimensionResource(id = R.dimen.tab_tray_list_bottom_padding)
|
||||
val isInMultiSelectMode = selectionMode is TabsTrayState.Mode.Select
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user