Fix drag and drop differ

pull/1718/head
Alex Baker 3 years ago
parent 3506a60ebc
commit fe48285be8

@ -48,15 +48,18 @@ interface DragAndDropDiffer<T, R> : ListUpdateCallback {
@ExperimentalCoroutinesApi @ExperimentalCoroutinesApi
fun initializeDiffer(list: List<T>): R { fun initializeDiffer(list: List<T>): R {
val initial = transform(list) val initial = transform(list)
scope.launch(Dispatchers.Main) { flow
flow .scan(Pair(initial, null), { last: Pair<R, DiffUtil.DiffResult?>, next: R ->
.scan(Pair(initial, null), { last: Pair<R, DiffUtil.DiffResult?>, next: R -> calculateDiff(last, next)
calculateDiff(last, next) })
}) .drop(1)
.drop(1) .flowOn(Executors.newSingleThreadExecutor().asCoroutineDispatcher())
.flowOn(Executors.newSingleThreadExecutor().asCoroutineDispatcher()) .onEach {
.collect { applyDiff(it) } withContext(Dispatchers.Main) {
} applyDiff(it)
}
}
.launchIn(scope)
return initial return initial
} }

Loading…
Cancel
Save