material-components-android
material-components-android copied to clipboard
[CenterAlignedTopAppBar] Unintended scrolling of `CenterAlignedTopAppBar` with `enterAlwaysScrollBehavior` when content does not exceed screen height
Description: When using the TopAppBarDefaults.enterAlwaysScrollBehavior() with CenterAlignedTopAppBar, the app bar reacts to scroll gestures even when the content does not exceed the screen height. This causes the app bar to scroll unnecessarily, leading to an undesirable user experience. Removing the scroll behavior resolves the issue, but it would be helpful if the CenterAlignedTopAppBar scroll behavior could automatically handle cases where content does not require scrolling.
Steps to Reproduce:
- Create a Scaffold with a
CenterAlignedTopAppBar
usingTopAppBarDefaults.enterAlwaysScrollBehavior()
. - Add content that does not exceed the screen height in the body of the Scaffold.
- Scroll up and down.
Expected behavior: The CenterAlignedTopAppBar should not scroll when the content does not exceed the screen height.
Source code:
@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun MyApp() {
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior()
Scaffold(modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), topBar = {
CenterAlignedTopAppBar(
modifier = Modifier, title = { Text("App Title") }, scrollBehavior = scrollBehavior
)
}) { innerPadding ->
Column(
modifier = Modifier
.padding(innerPadding)
.verticalScroll(rememberScrollState())
) {
Text("Content that does not exceed screen height")
}
}
}
Minimal sample app repro: https://github.com/thechinkysight/Pay_Your_Stay/commit/0bcdca890c95507652a2dfa1168c87428b7ff49e
I have provided the commit where I transition from enterAlwaysScrollBehavior()
as ScrollBehavior
to null
as ScrollBehavior
.
Android API version: API 35
Material Library version: composeBom = "2024.06.00"
Device: Pixel 8 Pro
Additional Information:
Removing the scroll behavior by setting it to null resolves the issue, but it would be beneficial if the CenterAlignedTopAppBar
scroll behavior could automatically handle cases where content does not require scrolling.