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

[Feature request] Add support for custom scroller #67

Open
bkonrad-check opened this issue Jan 16, 2025 · 2 comments
Open

[Feature request] Add support for custom scroller #67

bkonrad-check opened this issue Jan 16, 2025 · 2 comments

Comments

@bkonrad-check
Copy link

We would like to overwrite the logic for the scroller within our implementation. We got a sticky header with a nested scrolling, which should scroll up, when we drag and element down. However, when the library calls
scrollableState.animateScrollBy( diff, tween(durationMillis = duration.toInt(), easing = LinearEasing) )
the nested scrolling connection isn't working.

Due to this it would be nice, if the required Scroller could be an interface, which could be used for an custom implementation. This way we could pass the nested scroll connection or whatever we want to be scrolling to the rememberScroller and extend the logic you got.

Otherwise, maybe you have also an idea, why scrollableState.animateScrollBy doesn't work with the nested scrolling. lazyListState.animateScrollToItem(index) works fine.

Thanks in advance.

@Calvin-LL
Copy link
Owner

I'll look into this tomorrow. Any chance you can a screen recording of a sample project that has the problem you're running into? Not sure if I understand exactly what's happening.

@bkonrad-check
Copy link
Author

bkonrad-check commented Jan 17, 2025

nested.scrolling.issue.webm

this is basically the issue I got.
So manually scrolling works, but since I don't have control on the Scroller, I cannot scroll the top toolbar scrolling, when dragging.

Using this toolbar https://github.com/OyaCanli/tutorial_samples/blob/master/AppBarLayoutCompose/app/src/main/java/com/canlioya/appbarlayoutcompose/FlexibleTopBar.kt as sticky toolbar, integrated like this:

@OptIn(ExperimentalMaterial3Api::class)
@Composable
internal fun App() {
    PreComposeApp {
        ReorderableTheme {
            val navController = rememberNavigator()
            val showBackButton = navController.canGoBack.collectAsState(false)

            val topBarState = rememberTopAppBarState()
            val topAppBarScrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior(
                topBarState,
                snapAnimationSpec = null
            )

            CompositionLocalProvider(
                LocalMinimumInteractiveComponentSize provides Dp.Unspecified
            ) {
                Scaffold(
                    topBar = {
                        Column {
                            CenterAlignedTopAppBar(
                                title = { Text("Reorderable Demo") },
                                navigationIcon = { if (showBackButton.value) BackArrow(navController::popBackStack) },
                            )
                            FlexibleTopBar(
                                scrollBehavior = topAppBarScrollBehavior,
                                modifier = Modifier
                                    .fillMaxWidth()
                                    .background(Color.Blue)
                            ) {
                                Column(Modifier.height(150.dp)) {  }
                            }
                        }

                    },
                    content = {
                        Box(modifier = Modifier.padding(it)) {
                            NavHost(
                                navController,
                                modifier = Modifier.background(MaterialTheme.colorScheme.background)
                                    .nestedScroll(topAppBarScrollBehavior.nestedScrollConnection),
                                initialRoute = "main",
                            ) {
                                scene("main") { MainScreen(navController) }
                                scene("SimpleReorderableLazyColumn") { SimpleReorderableLazyColumnScreen() }
                                scene("ComplexReorderableLazyColumn") { ComplexReorderableLazyColumnScreen() }
                                scene("SimpleLongPressHandleReorderableLazyColumn") { SimpleLongPressHandleReorderableLazyColumnScreen() }
                                scene("SimpleReorderableLazyVerticalGrid") { SimpleReorderableLazyVerticalGridScreen() }
                                scene("SimpleReorderableLazyVerticalStaggeredGrid") { SimpleReorderableLazyVerticalStaggeredGridScreen() }
                                scene("ReorderableColumn") { ReorderableColumnScreen() }
                                scene("LongPressHandleReorderableColumn") { LongPressHandleReorderableColumnScreen() }
                                scene("SimpleReorderableLazyRow") { SimpleReorderableLazyRowScreen() }
                                scene("ComplexReorderableLazyRow") { ComplexReorderableLazyRowScreen() }
                                scene("SimpleReorderableLazyHorizontalGrid") { SimpleReorderableLazyHorizontalGridScreen() }
                                scene("SimpleReorderableLazyHorizontalStaggeredGrid") { SimpleReorderableLazyHorizontalStaggeredGridScreen() }
                                scene("ReorderableRow") { ReorderableRowScreen() }
                            }
                        }
                    }
                )
            }
        }
    }
}

Edit: To be clear, I want the possibility, that we can just use an own implementation for scroller, that way I could use the scroller to also scroll down the header by passing the topAppBarScrollBehavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants