Description
Short description of the issue:
MainScheduler
's DispatchQueue.isMain
contains false
on binding to BehaviorRelay
in context of UICollectionViewDiffableDataSource
's cellForRow function, which leads to UI blink with old data for a moment
Expected outcome:
Binding ViewModel's BehaviorRelay
to Cell's view should update it's UI instantly
What actually happens:
Cells are able to appear on screen with old data before value of BehaviorRelay
applies to Cell's views
Self contained code example that reproduces the issue:
Breakpoint should be in Reactive.swift
-> 42: base[keyPath: keyPath] = value
,
It will show the main problem of this issue
All code needed presents in ViewController
and TestCell
files. Everything else in this repo are default iOS app template from xCode
RxSwift/RxCocoa/RxBlocking/RxTest version/commit
RxSwift 6.5.0
Platform/Environment
- iOS
- macOS
- tvOS
- watchOS
- playgrounds
How easy is to reproduce? (chances of successful reproduce after running the self contained code)
- easy, 100% repro
- sometimes, 10%-100%
- hard, 2% - 10%
- extremely hard, %0 - 2%
Xcode version:
14.3
Installation method:
- CocoaPods
- Carthage
- Git submodules
I have multiple versions of Xcode installed:
(so we can know if this is a potential cause of your issue)
- yes (which ones)
- no
Level of RxSwift knowledge:
(this is so we can understand your level of knowledge
and formulate the response in an appropriate manner)
- just starting
- I have a small code base
- I have a significant code base
Some more details:
UICollectionViewDiffableDataSource
's cellForRow
function calls on queue named "Thread 1 Queue : com.apple.uikit.datasource.diffing (serial)", so it's not a 'main' queue, but it calls on Thread 1 which in fact IS the main thread
As experiment, I've added to MainScheduler
->scheduleInternal
's function additional condition - (Thread.current.isMainThread || DispatchQueue.isMain)
and it fixed my problem with diffableDataSource but I'm afraid it could damage anything else, so I'd like to find better solution to that problem