I've taken SwipeToRefresh implementation from JetNews into my own project. However, I feel like there is an important bug in the implementation that comes to surface when the state of the UI directly starts in refreshing (
loading) status.
refreshingState: Boolean,
is an argument to the SwipeToRefresh composable. It makes total sense that refreshing status is controlled by the parent. However, inner swipe state and this received state of refresh are combined together to call
onRefresh
callback inside the listener for swipe state change as follows:
val state = rememberSwipeableState(refreshingState) { newValue ->
// compare both copies of the swipe state before calling onRefresh(). This is a workaround.
if (newValue && !refreshingState) onRefresh()
true
}
However, something goes wrong in this lambda. Even if the
refreshingState
is changed from
true
to
false
by the parent, this lambda will keep reading it as the first time
remember
is called. If
refreshingState
was true at the start, it will remain true in the scope of this lambda until composition of
SwipeRefreshLayout
leaves the UI. As a workaround, I've changed
refreshingState
to a lambda that returns a boolean.