From 53edae1b6b466ef145d97b616a06534d09c2a35c Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Sat, 25 Nov 2023 22:27:49 +0700 Subject: [PATCH] Fix PTR initial refreshing state (#10173) --- .../core/components/material/PullRefresh.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/PullRefresh.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/PullRefresh.kt index dd854c3ac9..0a1dccc94c 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/PullRefresh.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/PullRefresh.kt @@ -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() {