electrolobzik
02/15/2024, 2:44 PMinit {
lifecycle.doOnResume {
log(" lifecycle.doOnResume")
store.accept(Intent.RefreshLocationStatus)
store.accept(Intent.RefreshSelfieStatus)
}
}
Arkadii Ivanov
02/15/2024, 2:46 PMelectrolobzik
02/15/2024, 2:52 PMArkadii Ivanov
02/15/2024, 3:17 PMinit
section.electrolobzik
02/15/2024, 3:20 PMArkadii Ivanov
02/15/2024, 3:24 PMelectrolobzik
02/15/2024, 5:07 PMArkadii Ivanov
04/23/2024, 8:24 PMprivate var root by lazy { ... }
) and the property is first accessed inside setContent { ... }
block. I will fix it soon.
Meantime, a workaround is to access the root
property right before calling setContent
, so that the root component is created earlier.electrolobzik
04/24/2024, 7:54 AMArkadii Ivanov
04/24/2024, 9:40 AMaddObserver
method, it may skip calling the callbacks synchronously (before addObserver call returns) if another dispatch is currently being performed. In other words, if you call addObserver
from another Lifecycle callback, the new callbacks are not called synchronously, but eventually once the current dispatch is finished.
This is the case when you wrap the root component creation in Lazy
and access it for the first time from setContent {}
block. The setContent {}
block is internally called from a Lifecycle callback. At this point the Jetpack Lifecycle is in RESUMED state. The root component, the stack and the child component are being created.
And there is a bug in Decompose MergedLifecycle, as it currently relies on parent Lifecycles to call callbacks synchronously on subscription, which is not always the case. As a result, it subscribes to both parent lifecycle1
and lifecycle2
, where lifecycle2
is a wrapped Jetpack Lifecycle in RESUMED state, but its callbacks are not called synchronously. First lifecycle1
dispatches its callbacks normally (triggered by Child Stack) - the resulting child Lifecycle goes INITIALIZED -> CREATED -> STARTED -> RESUMED, because it sees Jetpack Lifecycle is in RESUMED state. Then the Jetpack Lifecycle finally dispatches its callbacks, it calls onCreate first - the resulting Lifecycle goes RESUMED -> STARTED -> CREATED. Then it calls onStart and onResume - and the result Lifecycle goes CREATED -> STARTED -> RESUMED.
This might sound confusing, but here is a fix with tests: https://github.com/arkivanov/Decompose/pull/698. Hope it helps.electrolobzik
04/24/2024, 9:43 AM