mirror of
https://git.mihon.tech/mihonapp/mihon
synced 2024-11-21 20:55:41 +03:00
Tweak Preference.collectAsState
Co-authored-by: p
This commit is contained in:
parent
2beb89d531
commit
3bddb55385
1 changed files with 5 additions and 3 deletions
|
@ -4,10 +4,12 @@ import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.State
|
import androidx.compose.runtime.State
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import tachiyomi.core.common.preference.Preference
|
import tachiyomi.core.common.preference.Preference
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun <T> Preference<T>.collectAsState(): State<T> {
|
fun <T> Preference<T>.collectAsState(scope: CoroutineScope = rememberCoroutineScope()): State<T> {
|
||||||
val flow = remember(this) { changes() }
|
val flow = remember(this) { stateIn(scope) }
|
||||||
return flow.collectAsState(initial = get())
|
return flow.collectAsState()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue