Исправил скрытие реквестов в чат-листе как у архива Telegram
This commit is contained in:
@@ -2089,79 +2089,88 @@ fun ChatsListScreen(
|
|||||||
lastAutoScrolledVerificationId = verificationId
|
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(
|
LazyColumn(
|
||||||
state = chatListState,
|
state = chatListState,
|
||||||
modifier =
|
modifier =
|
||||||
Modifier.fillMaxSize()
|
Modifier.fillMaxSize()
|
||||||
.pointerInput(
|
.then(
|
||||||
requestsCount,
|
if (requestsCount > 0) Modifier.nestedScroll(requestsNestedScroll)
|
||||||
isRequestsVisible,
|
else Modifier
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.background(
|
.background(
|
||||||
listBackgroundColor
|
listBackgroundColor
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user