mirror of https://github.com/Ashinch/ReadYou.git
fix(worker): remove observer after leaving composition
This commit is contained in:
parent
6ed42a24e8
commit
8f4d24157e
|
@ -25,6 +25,7 @@ import androidx.compose.material.icons.rounded.Refresh
|
|||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.derivedStateOf
|
||||
import androidx.compose.runtime.getValue
|
||||
|
@ -115,8 +116,14 @@ fun FeedsPage(
|
|||
|
||||
val owner = LocalLifecycleOwner.current
|
||||
var isSyncing by remember { mutableStateOf(false) }
|
||||
homeViewModel.syncWorkLiveData.observe(owner) {
|
||||
it?.let { isSyncing = it.any { it.state == WorkInfo.State.RUNNING } }
|
||||
|
||||
DisposableEffect(owner) {
|
||||
homeViewModel.syncWorkLiveData.observe(owner) { workInfoList ->
|
||||
workInfoList.let {
|
||||
isSyncing = it.any { workInfo -> workInfo.state == WorkInfo.State.RUNNING }
|
||||
}
|
||||
}
|
||||
onDispose { homeViewModel.syncWorkLiveData.removeObservers(owner) }
|
||||
}
|
||||
|
||||
val infiniteTransition = rememberInfiniteTransition()
|
||||
|
|
|
@ -69,10 +69,17 @@ fun FlowPage(
|
|||
|
||||
val owner = LocalLifecycleOwner.current
|
||||
var isSyncing by remember { mutableStateOf(false) }
|
||||
homeViewModel.syncWorkLiveData.observe(owner) {
|
||||
it?.let { isSyncing = it.any { it.state == WorkInfo.State.RUNNING } }
|
||||
|
||||
DisposableEffect(owner) {
|
||||
homeViewModel.syncWorkLiveData.observe(owner) { workInfoList ->
|
||||
workInfoList.let {
|
||||
isSyncing = it.any { workInfo -> workInfo.state == WorkInfo.State.RUNNING }
|
||||
}
|
||||
}
|
||||
onDispose { homeViewModel.syncWorkLiveData.removeObservers(owner) }
|
||||
}
|
||||
|
||||
|
||||
val onToggleStarred: State<(ArticleWithFeed) -> Unit> = rememberUpdatedState {
|
||||
flowViewModel.updateStarredStatus(
|
||||
articleId = it.article.id,
|
||||
|
|
Loading…
Reference in New Issue