Fix PTR initial refreshing state (#10173)

This commit is contained in:
Ivan Iskandar 2023-11-25 22:27:49 +07:00 committed by GitHub
parent 356fc5b524
commit 53edae1b6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -46,6 +46,7 @@ fun PullRefresh(
content: @Composable () -> Unit,
) {
val state = rememberPullToRefreshState(
initialRefreshing = refreshing,
extraVerticalOffset = indicatorPadding.calculateTopPadding(),
enabled = enabled,
)
@ -90,6 +91,7 @@ fun PullRefresh(
@Composable
private fun rememberPullToRefreshState(
initialRefreshing: Boolean,
extraVerticalOffset: Dp,
positionalThreshold: Dp = 64.dp,
enabled: () -> Boolean = { true },
@ -108,7 +110,7 @@ private fun rememberPullToRefreshState(
),
) {
PullToRefreshStateImpl(
initialRefreshing = false,
initialRefreshing = initialRefreshing,
extraVerticalOffset = extraVerticalOffsetPx,
positionalThreshold = positionalThresholdPx,
enabled = enabled,
@ -133,18 +135,21 @@ private class PullToRefreshStateImpl(
) : PullToRefreshState {
override val progress get() = adjustedDistancePulled / positionalThreshold
override var verticalOffset by mutableFloatStateOf(0f)
override var verticalOffset by mutableFloatStateOf(if (initialRefreshing) refreshingVerticalOffset else 0f)
override var isRefreshing by mutableStateOf(initialRefreshing)
private val refreshingVerticalOffset: Float
get() = positionalThreshold + extraVerticalOffset
override fun startRefresh() {
isRefreshing = true
verticalOffset = positionalThreshold + extraVerticalOffset
verticalOffset = refreshingVerticalOffset
}
suspend fun startRefreshAnimated() {
isRefreshing = true
animateTo(positionalThreshold + extraVerticalOffset)
animateTo(refreshingVerticalOffset)
}
override fun endRefresh() {