compose-multiplatform icon indicating copy to clipboard operation
compose-multiplatform copied to clipboard

Desktop: Nested scrolling is not working properly

Open tchernykh opened this issue 4 years ago • 7 comments

NestedScrollConnectionSample from compose samples (link) is not working on desktop - toolbar suppose to move away when scrolling. Here in the sample onPreScroll method is never called. The sample works fine when run on Android.

@Composable
fun NestedScrollConnectionSample() {
    // here we use LazyColumn that has build-in nested scroll, but we want to act like a
    // parent for this LazyColumn and participate in its nested scroll.
    // Let's make a collapsing toolbar for LazyColumn
    val toolbarHeight = 48.dp
    val toolbarHeightPx = with(LocalDensity.current) { toolbarHeight.roundToPx().toFloat() }
    // our offset to collapse toolbar
    val toolbarOffsetHeightPx = remember { mutableStateOf(0f) }
    // now, let's create connection to the nested scroll system and listen to the scroll
    // happening inside child LazyColumn
    val nestedScrollConnection = remember {
        object : NestedScrollConnection {
            override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
                // try to consume before LazyColumn to collapse toolbar if needed, hence pre-scroll
                val delta = available.y
                val newOffset = toolbarOffsetHeightPx.value + delta
                toolbarOffsetHeightPx.value = newOffset.coerceIn(-toolbarHeightPx, 0f)
                // here's the catch: let's pretend we consumed 0 in any case, since we want
                // LazyColumn to scroll anyway for good UX
                // We're basically watching scroll without taking it
                return Offset.Zero
            }
        }
    }
    Box(
        Modifier
            .fillMaxSize()
            // attach as a parent to the nested scroll system
            .nestedScroll(nestedScrollConnection)
    ) {
        // our list with build in nested scroll support that will notify us about its scroll
        LazyColumn(contentPadding = PaddingValues(top = toolbarHeight)) {
            items(100) { index ->
                Text("I'm item $index", modifier = Modifier.fillMaxWidth().padding(16.dp))
            }
        }
        TopAppBar(
            modifier = Modifier
                .height(toolbarHeight)
                .offset { IntOffset(x = 0, y = toolbarOffsetHeightPx.value.roundToInt()) },
            title = { Text("toolbar offset is ${toolbarOffsetHeightPx.value}") }
        )
    }
}

Library version: 0.4.0-build182 OS: MacOS

tchernykh avatar May 09 '21 09:05 tchernykh

Any updates on this issue?

kyori19 avatar Nov 05 '21 06:11 kyori19

Any updates on this issue?

HuixingWong avatar Dec 15 '21 08:12 HuixingWong

@akurasov hello any plan for this issue?

HuixingWong avatar Dec 15 '21 09:12 HuixingWong

There are no specific plans about it yet

akurasov avatar Dec 15 '21 09:12 akurasov

Could this please be fixed?

Thomas-Vos avatar Apr 19 '22 23:04 Thomas-Vos

Are there any workarounds for this issue?

Thomas-Vos avatar Oct 27 '22 13:10 Thomas-Vos

Still no movement on this? It's been almost 2 years with no progress. Pull Refresh APIs are being introduced that rely on nested scroll, rendering them unusable on Desktop platforms.

christiandeange avatar Apr 07 '23 07:04 christiandeange

Any update on this? It makes TopAppBarDefaults.exitUntilCollapsedScrollBehavior() unusable in desktops, right?

MessiasLima avatar May 15 '23 15:05 MessiasLima

Does Compose desktop supports Scafford + TopAppBar nested scroll&collapsed effect? I try to make it in compose desktop but the app bar didn’t collapse as Android side when I scrolled the content.

jerryion avatar Jul 03 '23 06:07 jerryion

Did you guys found any workaround?

archiegq21 avatar Aug 06 '23 14:08 archiegq21

This bug still exists

GazimSoliev avatar Oct 13 '23 12:10 GazimSoliev

It was fixed in 1.6.0 branch, but we didn't merge this from upstream yet

MatkovIvan avatar Oct 13 '23 19:10 MatkovIvan

It was fixed in 1.6.0 branch, but we didn't merge this from upstream yet

Unfortunately, it's still not fixed in version 1.6.0-dev1405 and 1.6.0-beta01.

456634 avatar Feb 05 '24 17:02 456634

True, I've already checked this after the merge of Google's fix, but it seems that it requires changes from the multiplatform side too. I'll try to fix it before our 1.6 release, but no promises at the moment

UPD: it does NOT included in 1.6.0

MatkovIvan avatar Feb 05 '24 20:02 MatkovIvan