Status Update
Comments
co...@google.com <co...@google.com> #2
Hi Alex, that link is for Androidx source code, could you please share your video?
lp...@google.com <lp...@google.com> #3
This is because in the sample we are using remember
, whereas list state is using rememberSaveable
internally, which persists config changes.
I wonder if it is possible for us to infer the nested scroll based on just the list scroll, so that when we create the new scroll behavior on rotation we start with the app bar in the correct position - this seems more friendly than making users use rememberSaveable
here
lp...@google.com <lp...@google.com> #4
Andrey, curious if you have any thoughts here - for classes relating to list state, like in this case app bar behavior, should we just always be encouraging using rememberSaveable
for consistency with the list / scroll state?
al...@gmail.com <al...@gmail.com> #5
The issue exists in the current material catalog app (which is the code I linked too) so I figured they could just use that to reproduce it (since all you have to do is go to the top app bar screen in the catalog demo app, scroll the screen container, and then rotate the screen). But I could also create a standalone separate Android Studio project with the same code as what is in the material catalog app if that is the preferred format.
an...@google.com <an...@google.com> #6
LazyListState knows nothing about how other participants of nested scrolling mechanism used the unused deltas. So you will not be able to get this info from the restored LazyListState.
So
remember { TopAppBarDefaults.pinnedScrollBehavior() }
is the only source of truth for such info and if it is desired to be able to restore its state it should have rememberSaveable.
Also note that it is in fact not only about restoration after screen rotation. Does AppBar display the state you want it to when you initialise LazyColumn with not 0 offset straight away? I mean something like
LazyColumn(state = rememberLazyListState(initialFirstVisibleItemIndex = 2, initialFirstVisibleItemScrollOffset = 10))
al...@gmail.com <al...@gmail.com> #7
In response to
I think there would still be a problem using rememberSaveable
though. Because for example consider:
- You start out in landscape in a list screen
- You scroll down a tiny bit in the list screen causing the top app bar to animate its color
- You rotate the device to portrait (and let's assume the list is small enough such that the entire list is shown, making the list no longer scrollable).
The desired behavior here would be that the top app bar would switch back to its initial state since the scroll position in portrait has now become 0, right?
So seems like there would need to be some way to have the top app bar and scroll position linked somehow...
sg...@google.com <sg...@google.com>
sg...@google.com <sg...@google.com>
ap...@google.com <ap...@google.com> #8
Branch: androidx-main
commit e260141f2a679c33bfbe576d3a73fd4338d54d1a
Author: Shalom Gibly <sgibly@google.com>
Date: Fri May 06 12:50:36 2022
Adds support for saving a top app bar state
- Adds a TopAppBarScrollState and use it inside the
TopAppBarScrollBehavior implementations.
- The state is provides a Saver and used by a rememberSaveable to
maintain the app bar position on configuration change.
Test: AppBarTest
Bug: 216160958
Relnote: "Supports maintaining the top app bar position on configuration
change."
Change-Id: I104599fa724196bbf1fec1bfa424a2a70abaf2fe
M compose/material3/material3/api/restricted_current.txt
M compose/material3/material3/samples/src/main/java/androidx/compose/material3/samples/AppBarSamples.kt
M compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/AppBar.kt
M compose/material3/material3/api/current.txt
M compose/material3/material3/integration-tests/material3-catalog/src/main/java/androidx/compose/material3/catalog/library/ui/common/CatalogScaffold.kt
M compose/material3/material3/api/public_plus_experimental_current.txt
M compose/material3/material3/src/androidAndroidTest/kotlin/androidx/compose/material3/AppBarTest.kt
M compose/integration-tests/demos/src/main/java/androidx/compose/integration/demos/DemoApp.kt
sg...@google.com <sg...@google.com> #9
The main part of this issue was fixed, and we made changes to the API to support it.
Example usage:
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarScrollState())
SmallTopAppBar(
....
scrollBehavior = scrollBehavior
) ...
We may still have issues with cases mentioned at
al...@gmail.com <al...@gmail.com> #10
Does it make sense to create a separate issue to track the remaining bug?
Description
When you scroll a screen using a material3 top app bar, the top app bar's scroll container color changes. However, if you rotate the screen afterwards, the
LazyColumn
's scroll position will persist but the top app bar's color will reset back as if the screen was not scrolled at all.I attached a video illustrating the problem. The video is taken from the material demo app in AOSP, specifically this demo here (I made the app bar's scroll container color red to make it more obvious).