This commit is contained in:
GG Bond authored and renovate[bot] committed 2024-05-10 19:27:45 +08:00
1 parent fe1249630b
commit d628024637
3 files changed
+6 -8

No files matched your search

@@ -175,7 +175,7 @@ fun GalleryListScreen(lub: ListUrlBuilder, navigator: DestinationsNavigator) = c
var searchBarOffsetY by remember { mutableIntStateOf(0) }
var showSearchLayout by rememberSaveable { mutableStateOf(false) }
var category by rememberInDataStore("SearchCategory") { mutableIntStateOf(EhUtils.ALL_CATEGORY) }
var category by rememberInDataStore("SearchCategory") { EhUtils.ALL_CATEGORY }
var searchMethod by rememberSaveable { mutableIntStateOf(1) }
var advancedSearchOption by rememberSaveable { mutableStateOf(AdvancedSearchOption()) }
var imageUri by rememberSaveable { mutableStateOf<Uri?>(null) }
@@ -6,7 +6,6 @@ import androidx.compose.foundation.gestures.draggable2D
import androidx.compose.foundation.gestures.rememberDraggable2DState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
@@ -36,7 +35,7 @@ fun CircularLayout(
content: @Composable () -> Unit,
) {
val coroutineScope = rememberCoroutineScope()
var delta by rememberInDataStore("FavDialogTheta") { mutableFloatStateOf(0F) }
var delta by rememberInDataStore("FavDialogTheta") { 0F }
val state = rememberDraggable2DState {
val prevOfs = currentOfs
val prevTheta = currentTheta
@@ -3,7 +3,6 @@ package com.hippo.ehviewer.ui.tools
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisallowComposableCalls
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.currentCompositeKeyHash
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@@ -58,16 +57,16 @@ inline fun <reified T : Any> rememberInVM(
}
}
// Find out how make this work with any generic `Serializable` type
@Composable
inline fun <reified T> rememberInDataStore(
key: String,
crossinline defaultValue: @DisallowComposableCalls () -> MutableState<T>,
crossinline defaultValue: @DisallowComposableCalls () -> T,
) = with(dataStateFlow) {
remember {
val keyObj = byteArrayPreferencesKey(key)
value[keyObj]?.let { bytes ->
mutableStateOf(Cbor.decodeFromByteArray(bytes))
} ?: defaultValue()
val r = value[keyObj]?.let { bytes -> Cbor.decodeFromByteArray(bytes) } ?: defaultValue()
mutableStateOf(r)
}.also { value ->
DisposableEffect(key) {
onDispose {