2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-03 23:15:31 +00:00

Bug 1822193 - Scroll to the active tab when opening the Tabs Tray

This commit is contained in:
Noah Bond 2023-04-19 11:34:25 -07:00 committed by mergify[bot]
parent c9b5c9a7d4
commit 4e5757a0ac
2 changed files with 81 additions and 50 deletions

View File

@ -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,60 +146,77 @@ fun TabsTray(
) { position ->
when (Page.positionToPage(position)) {
Page.NormalTabs -> {
val showInactiveTabsAutoCloseDialog = shouldShowInactiveTabsAutoCloseDialog(inactiveTabs.size)
var showAutoCloseDialog by remember { mutableStateOf(showInactiveTabsAutoCloseDialog) }
if (normalTabs.isNotEmpty() || inactiveTabs.isNotEmpty()) {
val showInactiveTabsAutoCloseDialog =
shouldShowInactiveTabsAutoCloseDialog(inactiveTabs.size)
var showAutoCloseDialog by remember { mutableStateOf(showInactiveTabsAutoCloseDialog) }
val optionalInactiveTabsHeader: (@Composable () -> Unit)? = if (inactiveTabs.isEmpty()) {
null
} else {
{
InactiveTabsList(
inactiveTabs = inactiveTabs,
expanded = inactiveTabsExpanded,
showAutoCloseDialog = showAutoCloseDialog,
onHeaderClick = onInactiveTabsHeaderClick,
onDeleteAllButtonClick = onDeleteAllInactiveTabsClick,
onAutoCloseDismissClick = {
onInactiveTabAutoCloseDialogCloseButtonClick()
showAutoCloseDialog = !showAutoCloseDialog
},
onEnableAutoCloseClick = {
onEnableInactiveTabAutoCloseClick()
showAutoCloseDialog = !showAutoCloseDialog
},
onTabClick = onInactiveTabClick,
onTabCloseClick = onInactiveTabClose,
)
val optionalInactiveTabsHeader: (@Composable () -> Unit)? = if (inactiveTabs.isEmpty()) {
null
} else {
{
InactiveTabsList(
inactiveTabs = inactiveTabs,
expanded = inactiveTabsExpanded,
showAutoCloseDialog = showAutoCloseDialog,
onHeaderClick = onInactiveTabsHeaderClick,
onDeleteAllButtonClick = onDeleteAllInactiveTabsClick,
onAutoCloseDismissClick = {
onInactiveTabAutoCloseDialogCloseButtonClick()
showAutoCloseDialog = !showAutoCloseDialog
},
onEnableAutoCloseClick = {
onEnableInactiveTabAutoCloseClick()
showAutoCloseDialog = !showAutoCloseDialog
},
onTabClick = onInactiveTabClick,
onTabCloseClick = onInactiveTabClose,
)
}
}
}
if (showInactiveTabsAutoCloseDialog) {
onInactiveTabsAutoCloseDialogShown()
}
if (showInactiveTabsAutoCloseDialog) {
onInactiveTabsAutoCloseDialogShown()
}
TabLayout(
tabs = normalTabs,
displayTabsInGrid = displayTabsInGrid,
selectedTabId = selectedTabId,
selectionMode = multiselectMode,
onTabClose = onTabClose,
onTabMediaClick = onTabMediaClick,
onTabClick = handleTabClick,
onTabLongClick = onTabLongClick,
header = optionalInactiveTabsHeader,
)
TabLayout(
tabs = normalTabs,
displayTabsInGrid = displayTabsInGrid,
selectedTabId = selectedTabId,
selectionMode = multiselectMode,
onTabClose = onTabClose,
onTabMediaClick = onTabMediaClick,
onTabClick = handleTabClick,
onTabLongClick = onTabLongClick,
header = optionalInactiveTabsHeader,
)
} else {
Text(
text = "Empty state",
color = FirefoxTheme.colors.textPrimary,
style = FirefoxTheme.typography.body1,
)
}
}
Page.PrivateTabs -> {
TabLayout(
tabs = privateTabs,
displayTabsInGrid = displayTabsInGrid,
selectedTabId = selectedTabId,
selectionMode = multiselectMode,
onTabClose = onTabClose,
onTabMediaClick = onTabMediaClick,
onTabClick = handleTabClick,
onTabLongClick = onTabLongClick,
)
if (privateTabs.isNotEmpty()) {
TabLayout(
tabs = privateTabs,
displayTabsInGrid = displayTabsInGrid,
selectedTabId = selectedTabId,
selectionMode = multiselectMode,
onTabClose = onTabClose,
onTabMediaClick = onTabMediaClick,
onTabClick = handleTabClick,
onTabLongClick = onTabLongClick,
)
} else {
Text(
text = "Empty state",
color = FirefoxTheme.colors.textPrimary,
style = FirefoxTheme.typography.body1,
)
}
}
Page.SyncedTabs -> {
val syncedTabs = tabsTrayStore

View File

@ -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