From bf6ee6dc8708c67cfdab8567677d7db38e6995fb Mon Sep 17 00:00:00 2001 From: davotoula Date: Mon, 16 Mar 2026 19:01:51 +0100 Subject: [PATCH] Split the logic between onPreScroll and onPostScroll --- .../ui/components/ZonedSwipeModifier.kt | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZonedSwipeModifier.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZonedSwipeModifier.kt index 2579251446..b72c343154 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZonedSwipeModifier.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZonedSwipeModifier.kt @@ -60,12 +60,13 @@ fun Modifier.zonedDrawerSwipe( if (source != NestedScrollSource.UserInput) return Offset.Zero if (drawerOpened) return Offset(available.x, 0f) - // available.x > 0 means user is swiping right + // Non-first pages in the drawer zone: intercept before the + // pager consumes the delta to page backwards. if (available.x > 0f) { val wasOnFirstPage = gestureStartPage == 0 val isInPagerZone = gestureStartX < widthPx * PAGER_ZONE_FRACTION - if (wasOnFirstPage || !isInPagerZone) { + if (!wasOnFirstPage && !isInPagerZone) { drawerOpened = true openDrawer() return Offset(available.x, 0f) @@ -73,6 +74,24 @@ fun Modifier.zonedDrawerSwipe( } return Offset.Zero } + + override fun onPostScroll( + consumed: Offset, + available: Offset, + source: NestedScrollSource, + ): Offset { + if (source != NestedScrollSource.UserInput) return Offset.Zero + if (drawerOpened) return Offset(available.x, 0f) + + // First page: open drawer only with unconsumed right-swipe + // so child LazyRows can scroll first. + if (available.x > 0f && gestureStartPage == 0) { + drawerOpened = true + openDrawer() + return Offset(available.x, 0f) + } + return Offset.Zero + } } }