Status Update
Comments
an...@google.com <an...@google.com>
re...@gmail.com <re...@gmail.com> #2
Any news?
mb...@gmail.com <mb...@gmail.com> #3
compose is not ready!
an...@google.com <an...@google.com> #4
There is a simple workaround available
private val VerticalScrollConsumer = object : NestedScrollConnection {
override fun onPreScroll(available: Offset, source: NestedScrollSource) = available.copy(x = 0f)
}
private val HorizontalScrollConsumer = object : NestedScrollConnection {
override fun onPreScroll(available: Offset, source: NestedScrollSource) = available.copy(y = 0f)
}
fun Modifier.disableVerticalPointerInputScroll() = this.nestedScroll(VerticalScrollConsumer)
fun Modifier.disableHorizontalPointerInputScroll() = this.nestedScroll(HorizontalScrollConsumer)
Apply this modifier on LazyColumn/LazyRow in order to disable the touch based scroll.
I will keep this bug open in order to figure out if we want to add such modifier as a public api or add scrollEnabled param for the scrolling components.
re...@gmail.com <re...@gmail.com> #5
Thanks for the workaround.
I guess it's worth to override onPreFling
as well, otherwise any interaction with the list while the scroll is disabled will cause it to scroll when it is enabled again (if done fast by the user).
Example:
LazyColumn(
content = content,
state = state,
modifier = Modifier
.then(
if (!expanded) Modifier.disableVerticalPointerInputScroll() else Modifier
)
)
Fixed workaround:
private val VerticalScrollConsumer = object : NestedScrollConnection {
override fun onPreScroll(available: Offset, source: NestedScrollSource) = available.copy(x = 0f)
override suspend fun onPreFling(available: Velocity) = available.copy(x = 0f)
}
private val HorizontalScrollConsumer = object : NestedScrollConnection {
override fun onPreScroll(available: Offset, source: NestedScrollSource) = available.copy(y = 0f)
override suspend fun onPreFling(available: Velocity) = available.copy(y = 0f)
}
fun Modifier.disableVerticalPointerInputScroll() = this.nestedScroll(VerticalScrollConsumer)
fun Modifier.disableHorizontalPointerInputScroll() = this.nestedScroll(HorizontalScrollConsumer)
ma...@gmail.com <ma...@gmail.com> #6
This workaround still consumes the touches, so it is not available for some use cases (we have an overlay transparent LazyList that is moving over some other elements. We want this LazyList to not react to touches, but we also want touches to reach those element behind the list).
From what I see, there is no simple workaround for that.
What I would do is expose scrollEnabled
boolean on both LazyRow and LazyColumn that would be forwarded to the enabled
parameter of the Modifier.scrollable call inside LazyList method (which is currently always set to true). I can make a PR for that if Google accepts this.
an...@google.com <an...@google.com> #7
ap...@google.com <ap...@google.com> #8
Branch: androidx-main
commit f83773fff21e6a3c91bc665b06de2b3957d3339a
Author: Andrey Kulikov <andreykulikov@google.com>
Date: Wed Dec 15 20:19:16 2021
Add userScrollEnabled param for LazyColumn, LazyRow and LazyVerticalGrid
Relnote: New parameter `userScrollEnabled` was added to LazyColumn, LazyRow and LazyVerticalGrid in order to allow temporary or permanently disable the user initiated scroll via touch gestures or accessibility actions. Doing scroll programmatically via the methods on the state will still be allowed.
Fixes: 201150093
Test: new tests for lazy lists and grids
Change-Id: I7eae94b090ffc56269faea51ce84fe36b0ba9ae5
M compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/list/LazyListTest.kt
M compose/foundation/foundation/api/public_plus_experimental_current.txt
M compose/foundation/foundation/api/restricted_current.txt
M compose/foundation/foundation/api/current.txt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/LazyGrid.kt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/list/LazyList.kt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/LazyDsl.kt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/list/LazySemantics.kt
M compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/list/BaseLazyListTestWithOrientation.kt
M compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/LazyGridTest.kt
fr...@hotmail.com <fr...@hotmail.com> #9
as...@gmail.com <as...@gmail.com> #10
Just want to say that ScrollLayoutModifier
still calls constraints.assertNotNestingScrollableContainers(isVertical)
every time from what I see.
This means putting a LazyList
composable in a scrollable layout will still cause a crash.
an...@google.com <an...@google.com> #11
Nesting scrollable in the same direction containers is still not allowed, it can't work efficiently.
What was done as part of this bug is now you can disable the scroll triggered by the user gestures for LazyColumn. LazyColumn is still scrollable, you can scroll it programmatically via the methods on LazyListState
vi...@gmail.com <vi...@gmail.com> #12
an...@google.com <an...@google.com> #13
af...@gmail.com <af...@gmail.com> #14
Could we please also add support to ignore hardware arrow keys when userScrollEnabled
is set to false?
an...@google.com <an...@google.com> #15
Could you please file a separate feature request? Thanks
ma...@gmail.com <ma...@gmail.com> #16
userScrollEnabled
does not appear to work as described. It will still eat scroll events, preventing them from reaching composables behind it.
Here is a demo composable:
Box {
LazyRow() {
items(20) {
Box(
Modifier
.size(200.dp, 200.dp)
.padding(end = 32.dp)
.background(Color.Green))
}
}
LazyRow(modifier = Modifier.padding(top = 100.dp), userScrollEnabled = false) {
items(20) {
Box(
Modifier
.size(200.dp, 200.dp)
.padding(end = 32.dp)
.background(Color.Red.copy(alpha = 0.5f)))
}
}
}
With compose 1.2.0-alpha07
, you cannot scroll the top list by scrolling in the middle (where bottom list overlaps it), even though bottom list has scroll disabled.
Description
I need possibility to disable
LazyColumn
scrolling, and scroll it programmatically, like to sync it with some other scrollable view.scrollable
modifier hasenabled
parameter, and asLazyList
is using it underneath, it should be quite simple to add same parameter toLazyColumn
andLazyRow
.