mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-15 05:27:28 +01:00
Use IO dispatcher for some screen model work
Not sure if this is an ideal approach. If it is, we could migrate more usages to this.
This commit is contained in:
@@ -3,12 +3,20 @@ package eu.kanade.presentation.util
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.ProvidableCompositionLocal
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import cafe.adriel.voyager.core.model.ScreenModel
|
||||
import cafe.adriel.voyager.core.model.ScreenModelStore
|
||||
import cafe.adriel.voyager.core.screen.Screen
|
||||
import cafe.adriel.voyager.core.screen.ScreenKey
|
||||
import cafe.adriel.voyager.core.screen.uniqueScreenKey
|
||||
import cafe.adriel.voyager.core.stack.StackEvent
|
||||
import cafe.adriel.voyager.navigator.Navigator
|
||||
import cafe.adriel.voyager.transitions.ScreenTransition
|
||||
import kotlinx.coroutines.CoroutineName
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.plus
|
||||
import soup.compose.material.motion.animation.materialSharedAxisX
|
||||
import soup.compose.material.motion.animation.rememberSlideDistance
|
||||
|
||||
@@ -28,6 +36,18 @@ abstract class Screen : Screen {
|
||||
override val key: ScreenKey = uniqueScreenKey
|
||||
}
|
||||
|
||||
/**
|
||||
* A variant of ScreenModel.coroutineScope except with the IO dispatcher instead of the
|
||||
* main dispatcher.
|
||||
*/
|
||||
val ScreenModel.ioCoroutineScope: CoroutineScope
|
||||
get() = ScreenModelStore.getOrPutDependency(
|
||||
screenModel = this,
|
||||
name = "ScreenModelIoCoroutineScope",
|
||||
factory = { key -> CoroutineScope(Dispatchers.IO + SupervisorJob()) + CoroutineName(key) },
|
||||
onDispose = { scope -> scope.cancel() },
|
||||
)
|
||||
|
||||
interface AssistContentScreen {
|
||||
fun onProvideAssistUrl(): String?
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user