Починил повторное появление реквестов при прокрутке в чат-листе
This commit is contained in:
@@ -1802,8 +1802,6 @@ fun ChatsListScreen(
|
|||||||
remember(localDensity) { with(localDensity) { 56.dp.toPx() } }
|
remember(localDensity) { with(localDensity) { 56.dp.toPx() } }
|
||||||
val requestsHideThresholdPx =
|
val requestsHideThresholdPx =
|
||||||
remember(localDensity) { with(localDensity) { 16.dp.toPx() } }
|
remember(localDensity) { with(localDensity) { 16.dp.toPx() } }
|
||||||
val topOffsetTolerancePx =
|
|
||||||
remember(localDensity) { with(localDensity) { 3.dp.toPx() } }
|
|
||||||
|
|
||||||
AnimatedContent(
|
AnimatedContent(
|
||||||
targetState = showDownloadsScreen,
|
targetState = showDownloadsScreen,
|
||||||
@@ -2099,16 +2097,13 @@ fun ChatsListScreen(
|
|||||||
requestsCount,
|
requestsCount,
|
||||||
requestsRevealThresholdPx,
|
requestsRevealThresholdPx,
|
||||||
requestsHideThresholdPx,
|
requestsHideThresholdPx,
|
||||||
topOffsetTolerancePx,
|
|
||||||
hapticFeedback
|
hapticFeedback
|
||||||
) {
|
) {
|
||||||
var accumulatedPullDown = 0f
|
var accumulatedPullDown = 0f
|
||||||
var hapticSent = false
|
var hapticSent = false
|
||||||
object : androidx.compose.ui.input.nestedscroll.NestedScrollConnection {
|
object : androidx.compose.ui.input.nestedscroll.NestedScrollConnection {
|
||||||
fun isAtTop(): Boolean {
|
fun isAtTop(): Boolean {
|
||||||
return chatListState.firstVisibleItemIndex == 0 &&
|
return !chatListState.canScrollBackward
|
||||||
chatListState.firstVisibleItemScrollOffset <=
|
|
||||||
topOffsetTolerancePx.roundToInt()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPreScroll(
|
override fun onPreScroll(
|
||||||
@@ -2130,41 +2125,12 @@ fun ChatsListScreen(
|
|||||||
if (isRequestsVisible) {
|
if (isRequestsVisible) {
|
||||||
isRequestsVisible = false
|
isRequestsVisible = false
|
||||||
}
|
}
|
||||||
}
|
} else if (available.y > 0f && !isRequestsVisible && isAtTop()) {
|
||||||
return androidx.compose.ui.geometry.Offset.Zero
|
// Pull down from top should always reopen requests.
|
||||||
}
|
|
||||||
|
|
||||||
override fun onPostScroll(
|
|
||||||
consumed: androidx.compose.ui.geometry.Offset,
|
|
||||||
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
|
|
||||||
hapticSent = false
|
|
||||||
return androidx.compose.ui.geometry.Offset.Zero
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isRequestsVisible) {
|
|
||||||
accumulatedPullDown = 0f
|
|
||||||
hapticSent = false
|
|
||||||
return androidx.compose.ui.geometry.Offset.Zero
|
|
||||||
}
|
|
||||||
|
|
||||||
val pullDownDelta =
|
|
||||||
if (available.y > 0f && isAtTop())
|
|
||||||
available.y
|
|
||||||
else 0f
|
|
||||||
|
|
||||||
if (pullDownDelta > 0f) {
|
|
||||||
accumulatedPullDown =
|
accumulatedPullDown =
|
||||||
(accumulatedPullDown +
|
(accumulatedPullDown + available.y)
|
||||||
pullDownDelta)
|
|
||||||
.coerceAtMost(
|
.coerceAtMost(
|
||||||
requestsRevealThresholdPx *
|
requestsRevealThresholdPx * 2f
|
||||||
2f
|
|
||||||
)
|
)
|
||||||
if (accumulatedPullDown >= requestsRevealThresholdPx) {
|
if (accumulatedPullDown >= requestsRevealThresholdPx) {
|
||||||
isRequestsVisible = true
|
isRequestsVisible = true
|
||||||
@@ -2176,7 +2142,7 @@ fun ChatsListScreen(
|
|||||||
hapticSent = true
|
hapticSent = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (available.y < 0f || !isAtTop()) {
|
} else if (available.y <= 0f || !isAtTop()) {
|
||||||
accumulatedPullDown = 0f
|
accumulatedPullDown = 0f
|
||||||
hapticSent = false
|
hapticSent = false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user