feat: enhance swipe-back functionality in OtherProfileScreen and SwipeBackContainer
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user