How to use the new scrollable2d modifier mentioned...
# compose
n
How to use the new scrollable2d modifier mentioned in the 1.9.0-alpha03 release? Any samples on how to set offset to the child when scrolling diagonally.
Moreover, the Compose repository includes comprehensive samples that aim to cover every public API. https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]ava/androidx/compose/foundation/samples/Scrollable2DSample.kt
n
I think both the samples only showing the offset value in a Text component.
s
And?
The offset can be applied to a layout using Modifier.offset { /* offset logic */ }, causing the layout to move.
n
That's where my problem is. Can't be able to make it work. When I tried the entire component is jumping along the scroll instead of scrolling the content. Could you please share me how we can set the offset properly to scroll the content.
s
Screen_recording_20250522_115353.mp4
So far, I’ve made it work like this: the modifier doesn’t force the layout to match the size of its content. So, if you only apply
scrollable2D
, the content will be clipped by the parent’s bounds. I fixed this by adding the standard scrollable modifiers, and now it lays out correctly. However, I’m not sure if this is by design.
image.png,image.png
👍 1
t
Did you tried the wrapContent() modifier instead of the vertical/horizontalScroll one?
s
I tried, it didn’t help
t
Ok interesting that the scrallable2d behaves like this. Maybe a bug? I would expect that it will set the max size to infinity
🤷 1
n
Thanks @Sergey Y. Could you please help me with one more issue. How to set offset within the bounds of parent Composable?
s
You need to disable scrolling when the offset is negative (i.e., moved beyond the top-left bound) or when the offset is greater than or equal to the bottom-right bound of the scrollable content. But ideally, this should work automatically, otherwise, this modifier is just a version of the draggable one with inertia.
n
Okay, Thanks 👍
s
I suspect the modifier is still a work in progress and not fully implemented.
n
Might be. I think in my case it's better to wait until beta or rc release.
👍 1