Skip to content

Commit

Permalink
Use collectAsStateWithLifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
zsmb13 committed Nov 13, 2024
1 parent 5bdd7c5 commit f9293f1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand All @@ -34,6 +33,7 @@ import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import coil3.compose.AsyncImage
import com.jetbrains.kmpapp.data.MuseumObject
import com.jetbrains.kmpapp.screens.EmptyScreenContent
Expand All @@ -57,7 +57,7 @@ fun DetailScreen(
) {
val viewModel = koinViewModel<DetailViewModel>()

val obj by viewModel.getObject(objectId).collectAsState(initial = null)
val obj by viewModel.getObject(objectId).collectAsStateWithLifecycle(initialValue = null)
AnimatedContent(obj != null) { objectAvailable ->
if (objectAvailable) {
ObjectDetails(obj!!, onBackClick = navigateBack)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import androidx.compose.foundation.lazy.grid.items
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import coil3.compose.AsyncImage
import com.jetbrains.kmpapp.data.MuseumObject
import com.jetbrains.kmpapp.screens.EmptyScreenContent
Expand All @@ -37,7 +37,7 @@ fun ListScreen(
navigateToDetails: (objectId: Int) -> Unit
) {
val viewModel = koinViewModel<ListViewModel>()
val objects by viewModel.objects.collectAsState()
val objects by viewModel.objects.collectAsStateWithLifecycle()

AnimatedContent(objects.isNotEmpty()) { objectsAvailable ->
if (objectsAvailable) {
Expand Down

0 comments on commit f9293f1

Please sign in to comment.