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
fun initializeDiffer(list: List<T>): R {
val initial = transform(list)
scope.launch(Dispatchers.Main) {
flow
.scan(Pair(initial, null), { last: Pair<R, DiffUtil.DiffResult?>, next: R ->
calculateDiff(last, next)
})
.drop(1)
.flowOn(Executors.newSingleThreadExecutor().asCoroutineDispatcher())
.collect { applyDiff(it) }
}
flow
.scan(Pair(initial, null), { last: Pair<R, DiffUtil.DiffResult?>, next: R ->
calculateDiff(last, next)
})
.drop(1)
.flowOn(Executors.newSingleThreadExecutor().asCoroutineDispatcher())
.onEach {
withContext(Dispatchers.Main) {
applyDiff(it)
}
}
.launchIn(scope)
return initial
}

Loading…
Cancel
Save