Fix PTR initial refreshing state (#10173)
This commit is contained in:
parent
356fc5b524
commit
53edae1b6b
1 changed files with 9 additions and 4 deletions
|
@ -46,6 +46,7 @@ fun PullRefresh(
|
||||||
content: @Composable () -> Unit,
|
content: @Composable () -> Unit,
|
||||||
) {
|
) {
|
||||||
val state = rememberPullToRefreshState(
|
val state = rememberPullToRefreshState(
|
||||||
|
initialRefreshing = refreshing,
|
||||||
extraVerticalOffset = indicatorPadding.calculateTopPadding(),
|
extraVerticalOffset = indicatorPadding.calculateTopPadding(),
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
)
|
)
|
||||||
|
@ -90,6 +91,7 @@ fun PullRefresh(
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun rememberPullToRefreshState(
|
private fun rememberPullToRefreshState(
|
||||||
|
initialRefreshing: Boolean,
|
||||||
extraVerticalOffset: Dp,
|
extraVerticalOffset: Dp,
|
||||||
positionalThreshold: Dp = 64.dp,
|
positionalThreshold: Dp = 64.dp,
|
||||||
enabled: () -> Boolean = { true },
|
enabled: () -> Boolean = { true },
|
||||||
|
@ -108,7 +110,7 @@ private fun rememberPullToRefreshState(
|
||||||
),
|
),
|
||||||
) {
|
) {
|
||||||
PullToRefreshStateImpl(
|
PullToRefreshStateImpl(
|
||||||
initialRefreshing = false,
|
initialRefreshing = initialRefreshing,
|
||||||
extraVerticalOffset = extraVerticalOffsetPx,
|
extraVerticalOffset = extraVerticalOffsetPx,
|
||||||
positionalThreshold = positionalThresholdPx,
|
positionalThreshold = positionalThresholdPx,
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
|
@ -133,18 +135,21 @@ private class PullToRefreshStateImpl(
|
||||||
) : PullToRefreshState {
|
) : PullToRefreshState {
|
||||||
|
|
||||||
override val progress get() = adjustedDistancePulled / positionalThreshold
|
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)
|
override var isRefreshing by mutableStateOf(initialRefreshing)
|
||||||
|
|
||||||
|
private val refreshingVerticalOffset: Float
|
||||||
|
get() = positionalThreshold + extraVerticalOffset
|
||||||
|
|
||||||
override fun startRefresh() {
|
override fun startRefresh() {
|
||||||
isRefreshing = true
|
isRefreshing = true
|
||||||
verticalOffset = positionalThreshold + extraVerticalOffset
|
verticalOffset = refreshingVerticalOffset
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun startRefreshAnimated() {
|
suspend fun startRefreshAnimated() {
|
||||||
isRefreshing = true
|
isRefreshing = true
|
||||||
animateTo(positionalThreshold + extraVerticalOffset)
|
animateTo(refreshingVerticalOffset)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun endRefresh() {
|
override fun endRefresh() {
|
||||||
|
|
Reference in a new issue