我有一个StateFlow在我的应用程序的各个部分之间共享的协程。当我cancel在CoroutineScope下游收集器的,一个JobCancellationException被传播到StateFlow,并停止对所有当前和未来集电极发射值。
的StateFlow:
val songsRelay: Flow<List<Song>> by lazy {
MutableStateFlow<List<Song>?>(null).apply {
CoroutineScope(Dispatchers.IO)
.launch { songDataDao.getAll().distinctUntilChanged().collect { value = it } }
}.filterNotNull()
}
Run Code Online (Sandbox Code Playgroud)
我的代码中的典型“演示者”实现了以下基类:
abstract class BasePresenter<T : Any> : BaseContract.Presenter<T> {
var view: T? = null
private val job by lazy {
Job()
}
private val coroutineScope by lazy { CoroutineScope( job + Dispatchers.Main) }
override fun bindView(view: T) {
this.view = view
}
override fun unbindView() { …Run Code Online (Sandbox Code Playgroud) 我想要一个包含行列的框,其中填充了更多子项,这些子项接受单击(“CL”)和长按(“LO”)以进行缩放和拖动。使用pointerInputwithdetectTransforgestures我可以根据需要改变子布局。
var zoom by remember { mutableStateOf(1f) }
var offset by remember { mutableStateOf(Offset.Zero) }
val outer = (1..60).toList().chunked(6)
Box(Modifier
.fillMaxSize()
.pointerInput(Unit) {
//zoom in/out and move around
detectTransformGestures { gestureCentroid, gesturePan, gestureZoom, _ ->
val oldScale = zoom
val newScale = (zoom * gestureZoom).coerceIn(0.5f..5f)
offset =
(offset + gestureCentroid / oldScale) - (gestureCentroid / newScale + gesturePan / oldScale)
zoom = newScale
}
}) {
Box(
Modifier
.graphicsLayer {
translationX = -offset.x * zoom
translationY …Run Code Online (Sandbox Code Playgroud) intercept kotlin pinchzoom android-jetpack-compose android-jetpack-compose-gesture