Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desktop: Nested scrolling is not working properly #653

Closed
tchernykh opened this issue May 9, 2021 · 14 comments · Fixed by JetBrains/compose-multiplatform-core#1055
Closed
Assignees
Labels

Comments

@tchernykh
Copy link

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 tchernykh changed the title Nested scrolling is not working properly Desktop: Nested scrolling is not working properly May 9, 2021
@akurasov akurasov added bug Something isn't working desktop labels Jul 20, 2021
@kyori19
Copy link

kyori19 commented Nov 5, 2021

Any updates on this issue?

1 similar comment
@HuixingWong
Copy link

Any updates on this issue?

@HuixingWong
Copy link

@akurasov hello any plan for this issue?

@akurasov akurasov added the AK label Dec 15, 2021
@akurasov
Copy link
Contributor

There are no specific plans about it yet

@Thomas-Vos
Copy link
Contributor

Could this please be fixed?

@igordmn igordmn removed the AK label Oct 11, 2022
@Thomas-Vos
Copy link
Contributor

Are there any workarounds for this issue?

@christiandeange
Copy link
Contributor

christiandeange commented Apr 7, 2023

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.

@MessiasLima
Copy link

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

@igordmn igordmn assigned MatkovIvan and unassigned igordmn May 15, 2023
@jerryion
Copy link

jerryion commented Jul 3, 2023

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.

@archiegq21
Copy link

Did you guys found any workaround?

@GazimSoliev
Copy link

This bug still exists

@MatkovIvan
Copy link
Member

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

@456634
Copy link

456634 commented Feb 5, 2024

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.

@MatkovIvan
Copy link
Member

MatkovIvan commented Feb 5, 2024

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 added a commit to JetBrains/compose-multiplatform-core that referenced this issue Feb 14, 2024
## Proposed Changes

- Use `dispatchScroll` with a new `NestedScrollSource.Wheel` instead of
direct call of `scrollBy`/`dispatchRawDelta`
- Set scrolling priority to `MutatePriority.UserInput` during mouse
wheel scroll animation
- Move all scroll delta dispatching into a single coroutine
- Remove threshold (logic where small delta was applied without
animation), `shouldApplyImmediately` flag based on
`isPreciseWheelScroll` handles it instead.
- Wait `ProgressTimeout` after each mouse wheel event before resetting
`isScrollInProgress` flag
- Enable this logic by default (old "raw" dispatching failed our tests
on iOS)

## Testing

Test: Check "NestedScroll" page in mpp demo + unit tests

## Issues Fixed

Fixes JetBrains/compose-multiplatform#653
Fixes JetBrains/compose-multiplatform#1423
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.