I am using the new `LocalOverscrollFactory` API wi...
# compose
k
I am using the new
LocalOverscrollFactory
API with
OffsetOverscrollEffect
which is in the
OverscrollEffect
doc, the offset doesn't work unless I use the old
Modifier.overscroll
API. Now I use the
DrawModifierNode
instead of
LayoutModifierNode
to make offset, it works, but the touch gesture is wrong. When touching a item in list with overscroll offset, apparently, another item (located orignally, without offset) will be touched. How can I make the touch gesture account for the overscroll offset? Code details are in the thread.
Copy code
override val node: DelegatableNode =
    object : Modifier.Node(), LayoutModifierNode, DrawModifierNode {
        override val shouldAutoInvalidate: Boolean = false

        // don't work
        override fun MeasureScope.measure(
            measurable: Measurable,
            constraints: Constraints
        ): MeasureResult {
            val placeable = measurable.measure(constraints)
            return layout(placeable.width, placeable.height) {
                placeable.placeRelative(contentOffsetX.fastRoundToInt(), contentOffsetY.fastRoundToInt())
            }
        }

        // work
        override fun ContentDrawScope.draw() {
            translate(contentOffsetX, contentOffsetY) {
                this@draw.drawContent()
            }
        }
    }
l
There was a bug with not supporting LayoutModifierNode overscroll implementations, when you are setting overscroll on some scrolling containers like lazy list, but manually drawing it with Modifier.overscroll shouldn’t have this issue. This bug was fixed recently but landed in a release yet. Note that Modifier.overscroll is not an old API, it is still supported and intended to be used with new overscroll implementations For the draw translation, it probably depends where you are applying the overscroll, as you need to make sure it applies to everything that detects gestures as well
k
Thank you! I found the bug fix. I'm waiting for the release.