Drop explicitly fabbuilder reallocation, buildFab within snapshotFlow
This commit is contained in:
1 parent
9e0ea32296
commit
42e0b0aeab
3 files changed
+22
-17
No files matched your search
@@ -38,8 +38,8 @@ import androidx.compose.ui.util.lerp
|
||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
import moe.tarsin.coroutines.onEachLatest
|
||||
import moe.tarsin.coroutines.runSuspendCatching
|
||||
|
||||
enum class FabLayoutValue {
|
||||
@@ -128,18 +128,9 @@ fun FabLayout(
|
||||
}
|
||||
val builder by rememberUpdatedState(fabBuilder)
|
||||
|
||||
fun buildFab(builder: FabBuilder.() -> Unit) = buildList {
|
||||
builder { icon, action ->
|
||||
add(icon to action)
|
||||
}
|
||||
}
|
||||
|
||||
val secondaryFab by remember {
|
||||
snapshotFlow { builder }.map { one ->
|
||||
state.waitCollapse()
|
||||
buildFab(one)
|
||||
}
|
||||
}.collectAsState(remember { buildFab(fabBuilder) })
|
||||
snapshotFlow { buildFab(builder) }.onEachLatest { state.waitCollapse() }
|
||||
}.collectAsState(emptyList())
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
if (updatedExpanded && autoCancel) {
|
||||
Spacer(
|
||||
@@ -219,4 +210,10 @@ fun FabLayout(
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildFab(builder: FabBuilder.() -> Unit) = buildList {
|
||||
builder { icon, action ->
|
||||
add(icon to action)
|
||||
}
|
||||
}
|
||||
|
||||
const val FAB_ANIMATE_TIME = 300
|
||||
@@ -35,7 +35,6 @@ import androidx.compose.runtime.mutableStateMapOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.rememberUpdatedState
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.snapshotFlow
|
||||
@@ -221,7 +220,7 @@ fun FavouritesScreen(navigator: DestinationsNavigator) {
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
var hidden by remember { mutableStateOf(false) }
|
||||
val checkedInfoMap = remember { mutableStateMapOf<Long, BaseGalleryInfo>() }
|
||||
val selectMode by rememberUpdatedState(checkedInfoMap.isNotEmpty())
|
||||
val selectMode = checkedInfoMap.isNotEmpty()
|
||||
LockDrawer(selectMode)
|
||||
|
||||
SearchBarScreen(
|
||||
@@ -322,8 +321,6 @@ fun FavouritesScreen(navigator: DestinationsNavigator) {
|
||||
}.mapLatest { it }
|
||||
}.collectAsState(hidden)
|
||||
|
||||
// Explicitly reallocate fabBuilder lambda to recompose secondary fab
|
||||
val select = selectMode
|
||||
FabLayout(
|
||||
hidden = hideFab,
|
||||
expanded = expanded || selectMode,
|
||||
@@ -333,7 +330,7 @@ fun FavouritesScreen(navigator: DestinationsNavigator) {
|
||||
},
|
||||
autoCancel = !selectMode,
|
||||
) {
|
||||
if (!select) {
|
||||
if (!selectMode) {
|
||||
onClick(EhIcons.Default.GoTo) {
|
||||
coroutineScope.launch {
|
||||
val date = dialogState.showDatePicker()
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package moe.tarsin.coroutines
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.transformLatest
|
||||
|
||||
inline fun <T> Flow<T>.onEachLatest(
|
||||
crossinline action: suspend (T) -> Unit,
|
||||
): Flow<T> = transformLatest { value ->
|
||||
action(value)
|
||||
return@transformLatest emit(value)
|
||||
}
|
||||
Reference in new issue
Block a user