From 2501296d70d6ddeb6212d20b77e17c81496e51c6 Mon Sep 17 00:00:00 2001 From: k1ngsterr1 Date: Tue, 3 Mar 2026 20:47:32 +0500 Subject: [PATCH] feat: enhance swipe-back functionality in OtherProfileScreen and SwipeBackContainer --- .../main/java/com/rosetta/messenger/MainActivity.kt | 3 ++- .../messenger/ui/components/SwipeBackContainer.kt | 13 ++++++++----- .../messenger/ui/settings/OtherProfileScreen.kt | 6 ++++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/rosetta/messenger/MainActivity.kt b/app/src/main/java/com/rosetta/messenger/MainActivity.kt index 8fba527..354ab77 100644 --- a/app/src/main/java/com/rosetta/messenger/MainActivity.kt +++ b/app/src/main/java/com/rosetta/messenger/MainActivity.kt @@ -895,7 +895,8 @@ fun MainScreen( isVisible = isThemeVisible, onBack = { navStack = navStack.filterNot { it is Screen.Theme } }, isDarkTheme = isDarkTheme, - layer = 2 + layer = 2, + deferToChildren = true ) { ThemeScreen( isDarkTheme = isDarkTheme, diff --git a/app/src/main/java/com/rosetta/messenger/ui/components/SwipeBackContainer.kt b/app/src/main/java/com/rosetta/messenger/ui/components/SwipeBackContainer.kt index 7c2f6ef..cf7c8f7 100644 --- a/app/src/main/java/com/rosetta/messenger/ui/components/SwipeBackContainer.kt +++ b/app/src/main/java/com/rosetta/messenger/ui/components/SwipeBackContainer.kt @@ -88,6 +88,7 @@ fun SwipeBackContainer( layer: Int = 1, swipeEnabled: Boolean = true, propagateBackgroundProgress: Boolean = true, + deferToChildren: Boolean = false, content: @Composable () -> Unit ) { // 🚀 Lazy composition: skip ALL setup until the screen is opened for the first time. @@ -243,7 +244,7 @@ fun SwipeBackContainer( alpha = currentAlpha } .background(if (isDarkTheme) Color(0xFF1B1B1B) else Color.White) - .pointerInput(swipeEnabled, isAnimatingIn, isAnimatingOut) { + .pointerInput(swipeEnabled, isAnimatingIn, isAnimatingOut, deferToChildren) { if (!swipeEnabled || isAnimatingIn || isAnimatingOut) return@pointerInput val velocityTracker = VelocityTracker() @@ -268,12 +269,14 @@ fun SwipeBackContainer( var totalDragY = 0f var passedSlop = false - // Pre-slop: use Main pass so children (e.g. LazyRow) - // process first — if they consume, we back off. - // Post-claim: use Initial pass to intercept before children. + // deferToChildren=true: pre-slop uses Main pass so children + // (e.g. LazyRow) process first — if they consume, we back off. + // deferToChildren=false (default): always use Initial pass + // to intercept before children (original behavior). + // Post-claim: always Initial to block children. while (true) { val pass = - if (startedSwipe) + if (startedSwipe || !deferToChildren) PointerEventPass.Initial else PointerEventPass.Main val event = awaitPointerEvent(pass) diff --git a/app/src/main/java/com/rosetta/messenger/ui/settings/OtherProfileScreen.kt b/app/src/main/java/com/rosetta/messenger/ui/settings/OtherProfileScreen.kt index a162fc0..c96fb1b 100644 --- a/app/src/main/java/com/rosetta/messenger/ui/settings/OtherProfileScreen.kt +++ b/app/src/main/java/com/rosetta/messenger/ui/settings/OtherProfileScreen.kt @@ -199,15 +199,17 @@ fun OtherProfileScreen( } } - // Pager swipe → update tab + // Pager swipe → update tab + control swipe-back LaunchedEffect(pagerState) { snapshotFlow { pagerState.currentPage }.collect { page -> selectedTab = OtherProfileTab.entries[page] + // Swipe-back only on first tab (Media); on other tabs pager handles swipe + onSwipeBackEnabledChanged(page == 0 && !showImageViewer) } } LaunchedEffect(showImageViewer) { - onSwipeBackEnabledChanged(!showImageViewer) + onSwipeBackEnabledChanged(!showImageViewer && pagerState.currentPage == 0) } val backgroundColor = if (isDarkTheme) Color(0xFF1A1A1A) else Color(0xFFFFFFFF)