:wave: NestedScrollConnection Behavior Hi folks, ...
# compose
j
👋 NestedScrollConnection Behavior Hi folks, I have a scenario in my app where a
LazyColumn
contains a scrollable fixed height
TextField
. Additionally I have a top bar with pinned scroll behaviour. To achieve this behaviour I’m passing:
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()
to the
LazyColumn
using:
Modifier.nestedScroll(scrollBehavior.nestedScrollConnection)
. The issue I’m encountering is that scrolling inside the
TextField
(which is a child of the
LazyColumn
) triggers the pinned scroll behavior of my top bar. I want to prevent the
verticalScroll
inside the
TextField
from dispatching scroll changes to the parent `LazyColumn`’s
nestedScroll
connection. Is there a way to intercept and handle this behavior so that the scroll in the
TextField
is independent of the top bar scroll blob thinking fast? I’ll share a MRE code in 🧵
Copy code
@Composable
fun ScrollableTextFieldWithLazyColumn() {
    val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()

    Scaffold(
        topBar = {
            TopAppBar(
                title = { Text("Pinned Top Bar") },
                scrollBehavior = scrollBehavior
            )
        }
    ) { paddingValues ->
        LazyColumn(
            modifier = Modifier
                .padding(paddingValues)
                .nestedScroll(scrollBehavior.nestedScrollConnection)
        ) {
            item {
                Text("List Item 1")
            }
            item {
                TextField(
                    value = "Scrollable content inside TextField...",
                    onValueChange = {},
                    modifier = Modifier
                        .heightIn(max = 300.dp)
                        .verticalScroll(rememberScrollState()) // I don't want it to trigger pinned scroll behaviour
                )
            }
        }
    }
}