Change icon and badge stateIn behavior from WhileSubscriped to Lazy

This commit is contained in:
MM20 2023-04-21 15:03:33 +02:00
parent 8043d90cb5
commit 92fa92ff50
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
2 changed files with 3 additions and 3 deletions

View File

@ -78,11 +78,11 @@ class SearchableItemVM : ListItemViewModel(), KoinComponent {
val badge = searchable.flatMapLatest {
if (it == null) emptyFlow() else badgeService.getBadge(it)
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)
}.stateIn(viewModelScope, SharingStarted.Lazily, null)
val icon = searchable.combine(iconSize) { sh, sz -> sh to sz }.flatMapLatest { (s, size) ->
if (s == null || size == 0) emptyFlow() else iconService.getIcon(s, size)
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)
}.stateIn(viewModelScope, SharingStarted.Lazily, null)
val tags = searchable.flatMapLatest {
if (it == null) emptyFlow() else tagsService.getTags(it)

View File

@ -88,7 +88,7 @@ fun GridItem(
var bounds by remember { mutableStateOf(Rect.Zero) }
Column(modifier = modifier, horizontalAlignment = Alignment.CenterHorizontally) {
val badge by remember(item.key) { viewModel.badge }.collectAsStateWithLifecycle()
val badge by viewModel.badge.collectAsStateWithLifecycle()
val icon by viewModel.icon.collectAsStateWithLifecycle()
val launchOnPress = !item.preferDetailsOverLaunch