Skip to content

Commit

Permalink
Fix refresh indicator not showing up sometimes
Browse files Browse the repository at this point in the history
  • Loading branch information
chvp committed Feb 17, 2024
1 parent 50e9253 commit 458bf02
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions app/src/main/java/be/chvp/nanoledger/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,22 @@ fun MainContent(
val transactions by mainViewModel.transactions.observeAsState()
val isRefreshing by mainViewModel.isRefreshing.observeAsState()
val state = rememberPullToRefreshState()
if (state.isRefreshing) {
if (state.isRefreshing && !(isRefreshing ?: false)) {
LaunchedEffect(true) {
mainViewModel.refresh()
state.endRefresh()
}
} else if (!state.isRefreshing && (isRefreshing ?: false)) {
LaunchedEffect(true) {
state.startRefresh()
}
}
if (state.isRefreshing && !(isRefreshing ?: false)) {
if (state.isRefreshing) {
LaunchedEffect(true) {
state.endRefresh()
mainViewModel.refresh()
// Due to the way compositing works, we cancel the refresh in the
// first if (even if the first if is moved below this one, and then
// we have no way to undo the cancel).
state.startRefresh()
}
}
Box(modifier = Modifier.nestedScroll(state.nestedScrollConnection).padding(contentPadding)) {
Expand Down

0 comments on commit 458bf02

Please sign in to comment.