Stylianos Gakis
04/01/2026, 9:50 AMDisplayLinkClock from molecule in the context of my coroutineScope running this presenter.
I ended up having to use Dispatchers.Main + DisplayLinkClock as the CoroutineContext which is running the presenter to have the app not crash, but I am not sure if this is what I should be doing since then the entire persenter would be running on the main thread if I understand this correctly?
Anyone who has tackled this in the past has any ideas here perhaps?Stylianos Gakis
04/01/2026, 10:04 AMAndroidUiDispatcher.Main on my presenters already. So from my understanding, doing Dispatchers.Main should be the equivalent on iOS, so this should be finecurioustechizen
04/01/2026, 10:26 AMcurioustechizen
04/01/2026, 10:27 AMexpect abstract class MoleculeViewModel() : ViewModel {
val moleculeScope: CoroutineScope
}
// iOS implementation
actual abstract class MoleculeViewModel : ViewModel() {
actual val moleculeScope = CoroutineScope(
viewModelScope.coroutineContext +
Dispatchers.Main + // <- This prevents hangs on iOS. Without this, presenters collecting flows will happen immediately without a hop
DisplayLinkClock
)
}
// Android implementation
actual abstract class MoleculeViewModel actual constructor() : ViewModel() {
actual val moleculeScope: CoroutineScope = CoroutineScope(viewModelScope.coroutineContext + AndroidUiDispatcher.Main)
}Stylianos Gakis
04/01/2026, 10:41 AM// <- This prevents hangs on iOS. Without this, presenters collecting flows will happen immediately without a hopSurprised it even ran in the first place tbh because I am just getting a crash immediately before anything would be emitted from the presenter when I am missing it. But thanks a lot for sharing your snippets, then it sounds like I probably got the right idea then. Thanks a lot!
curioustechizen
04/01/2026, 10:45 AMStylianos Gakis
04/01/2026, 1:52 PMRyan Payne
04/04/2026, 12:28 PMcommonMain and switch the moleculeRecompositionMode and moleculeCoroutineContext per platform.Stylianos Gakis
04/05/2026, 12:16 AMRecompositionMode.ContextClock for the iOS target? Isn't the point of DisplayLink that it provides the necessary information inside the coroutine context so that you will actually get recompositions following that rather than just use the immediate alternative?Ryan Payne
04/05/2026, 1:53 AMRecompositionMode.ContextClock for both ios and android.Stylianos Gakis
04/17/2026, 11:56 AMRyan Payne
04/18/2026, 2:20 AMRecompositionMode.ContextClock on both Android and iOS. 🙂 It worked great 👍curioustechizen
04/29/2026, 8:58 AMContextClock but I cannot tell for sure.
My usecase is
1. I have a screen that upon entering starts collecting a flow. In the presenter this is in the present method as LaunchedEffect(Unit) { startCollectingMyFlow() }
2. This screen has a button that when pressed, opens a bottom sheet (this is a navigation event)
3. When the bottom sheet is closed, looks like the flow doesn't "resume" collection immediately. I see some missed emissions
curioustechizen
04/29/2026, 8:58 AMcurioustechizen
04/29/2026, 9:01 AMmoleculeCoroutineContext on iOS to use Dispatchers.Main and not Dispatchers.Main.immediate?Stylianos Gakis
04/29/2026, 9:34 AMcurioustechizen
04/29/2026, 9:38 AMcurioustechizen
04/29/2026, 10:45 AMRyan Payne
05/31/2026, 4:24 PM