Skip to content

Commit 3076c91

Browse files
committed
Bug 1929084 - Preserve scrolled state on the main menu when entering 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
1 parent 9786dcd commit 3076c91

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/menu/MenuDialogFragment.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import androidx.compose.animation.SizeTransform
2020
import androidx.compose.animation.core.FastOutLinearInEasing
2121
import androidx.compose.animation.core.LinearOutSlowInEasing
2222
import androidx.compose.animation.togetherWith
23+
import androidx.compose.foundation.rememberScrollState
2324
import androidx.compose.runtime.getValue
2425
import androidx.compose.runtime.mutableStateOf
2526
import androidx.compose.runtime.remember
@@ -182,6 +183,7 @@ class MenuDialogFragment : BottomSheetDialogFragment() {
182183
val webAppUseCases = components.useCases.webAppUseCases
183184

184185
val coroutineScope = rememberCoroutineScope()
186+
val scrollState = rememberScrollState()
185187

186188
val store = remember {
187189
MenuStore(
@@ -448,6 +450,7 @@ class MenuDialogFragment : BottomSheetDialogFragment() {
448450
availableAddons = availableAddons,
449451
browserWebExtensionMenuItems = browserWebExtensionMenuItem,
450452
),
453+
scrollState = scrollState,
451454
onMozillaAccountButtonClick = {
452455
view?.slideDown {
453456
store.dispatch(

mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/menu/compose/MainMenu.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

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

7+
import androidx.compose.foundation.ScrollState
78
import androidx.compose.foundation.background
89
import androidx.compose.foundation.layout.Column
910
import androidx.compose.runtime.Composable
@@ -39,6 +40,7 @@ import org.mozilla.fenix.theme.Theme
3940
* @param isWebCompatReporterSupported Whether or not the report broken site feature is supported.
4041
* @param isExtensionsProcessDisabled Whether or not the extensions process is disabled due to extension errors.
4142
* @param extensionsMenuItemDescription The label of extensions menu item description.
43+
* @param scrollState The [ScrollState] used for vertical scrolling.
4244
* @param onMozillaAccountButtonClick Invoked when the user clicks on Mozilla account button.
4345
* @param onHelpButtonClick Invoked when the user clicks on the help button.
4446
* @param onSettingsButtonClick Invoked when the user clicks on the settings button.
@@ -73,6 +75,7 @@ fun MainMenu(
7375
isWebCompatReporterSupported: Boolean,
7476
isExtensionsProcessDisabled: Boolean,
7577
extensionsMenuItemDescription: String,
78+
scrollState: ScrollState,
7679
onMozillaAccountButtonClick: () -> Unit,
7780
onHelpButtonClick: () -> Unit,
7881
onSettingsButtonClick: () -> Unit,
@@ -101,6 +104,7 @@ fun MainMenu(
101104
onSettingsButtonClick = onSettingsButtonClick,
102105
)
103106
},
107+
scrollState = scrollState,
104108
) {
105109
NewTabsMenuGroup(
106110
accessPoint = accessPoint,
@@ -396,6 +400,7 @@ private fun MenuDialogPreview() {
396400
showQuitMenu = true,
397401
isExtensionsProcessDisabled = true,
398402
extensionsMenuItemDescription = "No extensions enabled",
403+
scrollState = ScrollState(0),
399404
onMozillaAccountButtonClick = {},
400405
onHelpButtonClick = {},
401406
onSettingsButtonClick = {},
@@ -438,6 +443,7 @@ private fun MenuDialogPrivatePreview() {
438443
showQuitMenu = true,
439444
isExtensionsProcessDisabled = false,
440445
extensionsMenuItemDescription = "No extensions enabled",
446+
scrollState = ScrollState(0),
441447
onMozillaAccountButtonClick = {},
442448
onHelpButtonClick = {},
443449
onSettingsButtonClick = {},

mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/menu/compose/MenuScaffold.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

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

7+
import androidx.compose.foundation.ScrollState
78
import androidx.compose.foundation.layout.Arrangement
89
import androidx.compose.foundation.layout.Column
910
import androidx.compose.foundation.layout.ColumnScope
@@ -24,12 +25,14 @@ import org.mozilla.fenix.theme.FirefoxTheme
2425
* A scaffold for a menu UI that implements the basic layout structure with [header] and [content].
2526
*
2627
* @param modifier [Modifier] to be applied to the layout.
28+
* @param scrollState The [ScrollState] used for vertical scrolling.
2729
* @param header The Composable header block to render.
2830
* @param content The Composable content block to render.
2931
*/
3032
@Composable
3133
internal fun MenuScaffold(
3234
modifier: Modifier = Modifier,
35+
scrollState: ScrollState = rememberScrollState(),
3336
header: @Composable ColumnScope.() -> Unit,
3437
content: @Composable ColumnScope.() -> Unit,
3538
) {
@@ -44,8 +47,6 @@ internal fun MenuScaffold(
4447
Spacer(modifier = Modifier.height(8.dp))
4548
}
4649

47-
val scrollState = rememberScrollState()
48-
4950
if (scrollState.value != 0) {
5051
Divider(color = FirefoxTheme.colors.borderPrimary)
5152
}

0 commit comments

Comments
 (0)