Hi, I tried to find here how someone solve PullRef...
# compose
y
Hi, I tried to find here how someone solve PullRefreshIndicator but unsuccessfully. I try to migrate to material from accompanist and in material is not LinearProgressIndicator 🤷. And if I see correctly there is only CircularProgressIndicator. Is anyway how to rewrite it to material way or it is so early? Thanks! ❤️ ✏️
a
y
@Andrew Neal Thats nice, but … accompanist state has
Copy code
swipeRefreshState.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 performed
aka
Copy code
onDrawBehind {
    val distance = refreshTriggerDistance.toPx()
    val progress = (swipeRefreshState.indicatorOffset / distance).coerceIn(0f, 1f)
a
You'll just want to track the state yourself now - that sample shows you how to. Create some state to keep track of your progress:
Copy code
var currentDistance by remember { mutableStateOf(0f) }
val progress = currentDistance / threshold
Calculate the current drag distance:
Copy code
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`:
Copy code
Modifier.pullRefresh(::onPull, ::onRelease)
y
you are faster than lightning! 😄 I just understood it from that example, I wanted to delete it here and you already wrote it here for me too ... thank you very much! I love this community ❤️