asyncState takes produce

This commit is contained in:
Dude so hot authored and renovate[bot] committed 2025-01-16 20:22:34 +08:00
1 parent cbbbc7f211
commit be55f3cf90
5 files changed
+7 -7

No files matched your search

@@ -130,7 +130,7 @@ fun FabLayout(
val builder by rememberUpdatedState(fabBuilder)
val secondaryFab by asyncState(
record = { buildFab(builder) },
produce = { buildFab(builder) },
transform = { onEachLatest { state.collapse(MutatePriority.PreventUserInput) } },
)
@@ -634,7 +634,7 @@ fun AnimatedVisibilityScope.DownloadsScreen(navigator: DestinationsNavigator) =
}
val hideFab by asyncState(
record = { fabHidden },
produce = { fabHidden },
transform = {
onEachLatest { hide ->
if (!hide) delay(FAB_ANIMATE_TIME.toLong())
@@ -332,7 +332,7 @@ fun AnimatedVisibilityScope.FavouritesScreen(navigator: DestinationsNavigator) =
}
val hideFab by asyncState(
record = { fabHidden },
produce = { fabHidden },
transform = {
onEachLatest { hide: Boolean ->
if (!hide) delay(FAB_ANIMATE_TIME.toLong())
@@ -596,7 +596,7 @@ fun AnimatedVisibilityScope.GalleryListScreen(lub: ListUrlBuilder, navigator: De
val outOfRange = stringResource(R.string.error_out_of_range)
val hideFab by asyncState(
record = { fabHidden },
produce = { fabHidden },
transform = {
onEachLatest { hide: Boolean ->
if (!hide) delay(FAB_ANIMATE_TIME.toLong())
@@ -9,10 +9,10 @@ import kotlinx.coroutines.flow.Flow
@Composable
fun <T : Any> asyncState(
record: () -> T,
produce: () -> T,
transform: Flow<T>.() -> Flow<T> = { this },
) = remember(transform, record) {
Snapshot.withoutReadObservation(record) to transform(snapshotFlow(record))
) = remember(transform, produce) {
Snapshot.withoutReadObservation(produce) to transform(snapshotFlow(produce))
}.let { (initial, flow) ->
flow.collectAsState(initial)
}