Skip to content

Commit

Permalink
feat: 大元のViewGroupのvisibilityを制御することによって、パフォーマンスを改善
Browse files Browse the repository at this point in the history
  • Loading branch information
pantasystem committed Jul 10, 2023
1 parent b830d2b commit c718559
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package net.pantasystem.milktea.note.media.viewmodel

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import net.pantasystem.milktea.model.file.FilePreviewSource
import net.pantasystem.milktea.model.file.isSensitive
import net.pantasystem.milktea.model.setting.Config
Expand All @@ -26,6 +31,8 @@ class MediaViewData(
})
val files: StateFlow<List<PreviewAbleFile>> = _files

val isEmpty = _files.map { it.isEmpty() }.stateIn(coroutineScope, SharingStarted.WhileSubscribed(5_000), true)

val fileOne = _files.map {
it.getOrNull(0)
}.stateIn(coroutineScope, SharingStarted.WhileSubscribed(5_000), null)
Expand Down
4 changes: 3 additions & 1 deletion modules/features/note/src/main/res/layout/media_preview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
rect="@{30F}" >
rect="@{30F}"
memoVisibility="@{ media.isEmpty() ? View.GONE : View.VISIBLE }"
>

<LinearLayout
android:layout_width="0dp"
Expand Down

0 comments on commit c718559

Please sign in to comment.