yogaboy
04/06/2023, 3:28 PMAndrew Neal
04/06/2023, 3:55 PMyogaboy
04/06/2023, 8:41 PMswipeRefreshState.indicatorOffset
and pullRefreshState has everything private or internal 😢 . Now I am not able to measure how far I pull .. coz I used it to drawRect indicator and when it was on the entire width of the screen, then linear progress indicator started and the pull was performedonDrawBehind {
val distance = refreshTriggerDistance.toPx()
val progress = (swipeRefreshState.indicatorOffset / distance).coerceIn(0f, 1f)
Andrew Neal
04/06/2023, 8:55 PMvar currentDistance by remember { mutableStateOf(0f) }
val progress = currentDistance / threshold
Calculate the current drag distance:
fun onPull(pullDelta: Float): Float = when {
refreshing -> 0f
else -> {
val newOffset = (currentDistance + pullDelta).coerceAtLeast(0f)
val dragConsumed = newOffset - currentDistance
currentDistance = newOffset
dragConsumed
}
}
Pass your callback into `Modifier.pullRefresh`:
Modifier.pullRefresh(::onPull, ::onRelease)
yogaboy
04/06/2023, 9:06 PM