Don't collect If isInFavScene
This commit is contained in:
1 parent
3479498c6c
commit
f864d65d98
2 files changed
+13
-16
No files matched your search
@@ -66,9 +66,6 @@ fun GalleryInfoListItem(
|
||||
modifier = Modifier.aspectRatio(DEFAULT_ASPECT).fillMaxSize(),
|
||||
)
|
||||
}
|
||||
val showFav by FavouriteStatusRouter.collectAsState(info) {
|
||||
it != NOT_FAVORITED && !isInFavScene
|
||||
}
|
||||
ConstraintLayout(modifier = Modifier.padding(8.dp, 4.dp).fillMaxSize()) {
|
||||
val (titleRef, uploaderRef, ratingRef, categoryRef, postedRef, favRef, iconsRef) = createRefs()
|
||||
Text(
|
||||
@@ -145,14 +142,16 @@ fun GalleryInfoListItem(
|
||||
text = info.favoriteNote.orEmpty(),
|
||||
fontStyle = FontStyle.Italic,
|
||||
)
|
||||
}
|
||||
if (showFav) {
|
||||
Icon(
|
||||
Icons.Default.Favorite,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(16.dp),
|
||||
)
|
||||
Text(text = info.favoriteName.orEmpty())
|
||||
} else {
|
||||
val showFav by FavouriteStatusRouter.collectAsState(info) { it != NOT_FAVORITED }
|
||||
if (showFav) {
|
||||
Icon(
|
||||
Icons.Default.Favorite,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(16.dp),
|
||||
)
|
||||
Text(text = info.favoriteName.orEmpty())
|
||||
}
|
||||
}
|
||||
}
|
||||
Text(
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.hippo.ehviewer.util
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisallowComposableCalls
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.remember
|
||||
import com.hippo.ehviewer.EhDB
|
||||
@@ -25,7 +26,6 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.asSharedFlow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.transform
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@@ -46,11 +46,9 @@ object FavouriteStatusRouter {
|
||||
|
||||
val globalFlow = _globalFlow.asSharedFlow()
|
||||
|
||||
@Stable
|
||||
@Composable
|
||||
inline fun <R> collectAsState(initial: GalleryInfo, crossinline transform: @DisallowComposableCalls (Int) -> R) = remember {
|
||||
globalFlow.transform { (gid, slot) -> if (initial.gid == gid) emit(slot) }
|
||||
.map { transform(it) }
|
||||
// We cannot use .map(transform) otherwise we will get a strange NPE
|
||||
// TODO: Report to kotlin compiler issue-tracker
|
||||
globalFlow.transform { (gid, slot) -> if (initial.gid == gid) emit(transform(slot)) }
|
||||
}.collectAsState(transform(initial.favoriteSlot))
|
||||
}
|
||||
Reference in new issue
Block a user