diff --git a/app/src/main/java/be/chvp/nanoledger/ui/main/MainActivity.kt b/app/src/main/java/be/chvp/nanoledger/ui/main/MainActivity.kt index 5465582..fd9dec0 100644 --- a/app/src/main/java/be/chvp/nanoledger/ui/main/MainActivity.kt +++ b/app/src/main/java/be/chvp/nanoledger/ui/main/MainActivity.kt @@ -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)) {