Skip to content

Commit

Permalink
Bug 1929084 - Preserve scrolled state on the main menu when entering …
Browse files Browse the repository at this point in the history
…back from the sub-menu. r=giorga,android-reviewers

Preserve the scrolled state of the main menu so that when returning to it from a sub-menu, the main menu's scrolled state does not get reset.

Differential Revision: https://phabricator.services.mozilla.com/D234805
  • Loading branch information
sm0ca committed Jan 20, 2025
1 parent 9786dcd commit 3076c91
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.animation.SizeTransform
import androidx.compose.animation.core.FastOutLinearInEasing
import androidx.compose.animation.core.LinearOutSlowInEasing
import androidx.compose.animation.togetherWith
import androidx.compose.foundation.rememberScrollState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -182,6 +183,7 @@ class MenuDialogFragment : BottomSheetDialogFragment() {
val webAppUseCases = components.useCases.webAppUseCases

val coroutineScope = rememberCoroutineScope()
val scrollState = rememberScrollState()

val store = remember {
MenuStore(
Expand Down Expand Up @@ -448,6 +450,7 @@ class MenuDialogFragment : BottomSheetDialogFragment() {
availableAddons = availableAddons,
browserWebExtensionMenuItems = browserWebExtensionMenuItem,
),
scrollState = scrollState,
onMozillaAccountButtonClick = {
view?.slideDown {
store.dispatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package org.mozilla.fenix.components.menu.compose

import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -39,6 +40,7 @@ import org.mozilla.fenix.theme.Theme
* @param isWebCompatReporterSupported Whether or not the report broken site feature is supported.
* @param isExtensionsProcessDisabled Whether or not the extensions process is disabled due to extension errors.
* @param extensionsMenuItemDescription The label of extensions menu item description.
* @param scrollState The [ScrollState] used for vertical scrolling.
* @param onMozillaAccountButtonClick Invoked when the user clicks on Mozilla account button.
* @param onHelpButtonClick Invoked when the user clicks on the help button.
* @param onSettingsButtonClick Invoked when the user clicks on the settings button.
Expand Down Expand Up @@ -73,6 +75,7 @@ fun MainMenu(
isWebCompatReporterSupported: Boolean,
isExtensionsProcessDisabled: Boolean,
extensionsMenuItemDescription: String,
scrollState: ScrollState,
onMozillaAccountButtonClick: () -> Unit,
onHelpButtonClick: () -> Unit,
onSettingsButtonClick: () -> Unit,
Expand Down Expand Up @@ -101,6 +104,7 @@ fun MainMenu(
onSettingsButtonClick = onSettingsButtonClick,
)
},
scrollState = scrollState,
) {
NewTabsMenuGroup(
accessPoint = accessPoint,
Expand Down Expand Up @@ -396,6 +400,7 @@ private fun MenuDialogPreview() {
showQuitMenu = true,
isExtensionsProcessDisabled = true,
extensionsMenuItemDescription = "No extensions enabled",
scrollState = ScrollState(0),
onMozillaAccountButtonClick = {},
onHelpButtonClick = {},
onSettingsButtonClick = {},
Expand Down Expand Up @@ -438,6 +443,7 @@ private fun MenuDialogPrivatePreview() {
showQuitMenu = true,
isExtensionsProcessDisabled = false,
extensionsMenuItemDescription = "No extensions enabled",
scrollState = ScrollState(0),
onMozillaAccountButtonClick = {},
onHelpButtonClick = {},
onSettingsButtonClick = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package org.mozilla.fenix.components.menu.compose

import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
Expand All @@ -24,12 +25,14 @@ import org.mozilla.fenix.theme.FirefoxTheme
* A scaffold for a menu UI that implements the basic layout structure with [header] and [content].
*
* @param modifier [Modifier] to be applied to the layout.
* @param scrollState The [ScrollState] used for vertical scrolling.
* @param header The Composable header block to render.
* @param content The Composable content block to render.
*/
@Composable
internal fun MenuScaffold(
modifier: Modifier = Modifier,
scrollState: ScrollState = rememberScrollState(),
header: @Composable ColumnScope.() -> Unit,
content: @Composable ColumnScope.() -> Unit,
) {
Expand All @@ -44,8 +47,6 @@ internal fun MenuScaffold(
Spacer(modifier = Modifier.height(8.dp))
}

val scrollState = rememberScrollState()

if (scrollState.value != 0) {
Divider(color = FirefoxTheme.colors.borderPrimary)
}
Expand Down

0 comments on commit 3076c91

Please sign in to comment.