From bd6e033ed34ca93fffc3dc086ef1e274d7159a25 Mon Sep 17 00:00:00 2001 From: k1ngsterr1 Date: Thu, 19 Mar 2026 19:53:07 +0500 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=81=D0=BA=D1=80=D1=8B=D1=82=D0=B8=D0=B5=20=D1=80?= =?UTF-8?q?=D0=B5=D0=BA=D0=B2=D0=B5=D1=81=D1=82=D0=BE=D0=B2=20=D0=B2=20?= =?UTF-8?q?=D1=87=D0=B0=D1=82-=D0=BB=D0=B8=D1=81=D1=82=D0=B5=20=D0=BA?= =?UTF-8?q?=D0=B0=D0=BA=20=D1=83=20=D0=B0=D1=80=D1=85=D0=B8=D0=B2=D0=B0=20?= =?UTF-8?q?Telegram?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../messenger/ui/chats/ChatsListScreen.kt | 147 ++++++++++-------- 1 file changed, 78 insertions(+), 69 deletions(-) diff --git a/app/src/main/java/com/rosetta/messenger/ui/chats/ChatsListScreen.kt b/app/src/main/java/com/rosetta/messenger/ui/chats/ChatsListScreen.kt index 49029a5..d050733 100644 --- a/app/src/main/java/com/rosetta/messenger/ui/chats/ChatsListScreen.kt +++ b/app/src/main/java/com/rosetta/messenger/ui/chats/ChatsListScreen.kt @@ -2089,79 +2089,88 @@ fun ChatsListScreen( lastAutoScrolledVerificationId = verificationId } + val requestsNestedScroll = + remember( + requestsCount, + chatListState, + requestsRevealThresholdPx, + requestsHideThresholdPx, + hapticFeedback + ) { + var accumulatedPullDown = 0f + var accumulatedPullUp = 0f + object : androidx.compose.ui.input.nestedscroll.NestedScrollConnection { + override fun onPreScroll( + available: androidx.compose.ui.geometry.Offset, + source: androidx.compose.ui.input.nestedscroll.NestedScrollSource + ): androidx.compose.ui.geometry.Offset { + if (source != androidx.compose.ui.input.nestedscroll.NestedScrollSource.Drag || + requestsCount <= 0 + ) { + accumulatedPullDown = 0f + accumulatedPullUp = 0f + return androidx.compose.ui.geometry.Offset.Zero + } + + val atTop = !chatListState.canScrollBackward + val nearTop = + chatListState.firstVisibleItemIndex == 0 + + if (available.y < 0f && + isRequestsVisible && + (atTop || + nearTop) + ) { + accumulatedPullUp += -available.y + accumulatedPullDown = 0f + if (accumulatedPullUp >= requestsHideThresholdPx) { + isRequestsVisible = false + accumulatedPullUp = 0f + } + return androidx.compose.ui.geometry.Offset.Zero + } + accumulatedPullUp = 0f + + if (available.y > 0f && atTop && !isRequestsVisible) { + accumulatedPullDown = + (accumulatedPullDown + available.y) + .coerceAtMost( + requestsRevealThresholdPx + ) + if (accumulatedPullDown >= requestsRevealThresholdPx) { + isRequestsVisible = true + accumulatedPullDown = 0f + accumulatedPullUp = 0f + hapticFeedback.performHapticFeedback( + HapticFeedbackType.LongPress + ) + } + } else if (available.y <= 0f || !atTop) { + accumulatedPullDown = 0f + } + + return androidx.compose.ui.geometry.Offset.Zero + } + + override suspend fun onPostFling( + consumed: androidx.compose.ui.unit.Velocity, + available: androidx.compose.ui.unit.Velocity + ): androidx.compose.ui.unit.Velocity { + accumulatedPullDown = 0f + accumulatedPullUp = 0f + return androidx.compose.ui.unit.Velocity.Zero + } + } + } + LazyColumn( state = chatListState, modifier = Modifier.fillMaxSize() - .pointerInput( - requestsCount, - isRequestsVisible, - chatListState, - requestsRevealThresholdPx, - requestsHideThresholdPx - ) { - if (requestsCount <= 0) return@pointerInput - - awaitEachGesture { - val down = - awaitFirstDown( - requireUnconsumed = - false - ) - var accumulatedPullDown = 0f - - while (true) { - val event = - awaitPointerEvent() - val change = - event.changes - .firstOrNull { - it.id == - down - .id - } - ?: break - if (change.changedToUpIgnoreConsumed()) { - break - } - - val deltaY = - change.positionChange() - .y - val atTop = - !chatListState.canScrollBackward - - if (isRequestsVisible && - atTop && - deltaY < - -requestsHideThresholdPx - ) { - isRequestsVisible = false - accumulatedPullDown = 0f - break - } - - if (!isRequestsVisible && - atTop && - deltaY > 0f - ) { - accumulatedPullDown += - deltaY - if (accumulatedPullDown >= - requestsRevealThresholdPx - ) { - isRequestsVisible = true - hapticFeedback.performHapticFeedback( - HapticFeedbackType.LongPress - ) - break - } - } else if (deltaY < 0f || !atTop) { - accumulatedPullDown = 0f - } - } - } - } + .then( + if (requestsCount > 0) Modifier.nestedScroll(requestsNestedScroll) + else Modifier + ) .background( listBackgroundColor )