@@ -113,6 +113,10 @@ public class LayeredDialogSessions private constructor(
113113
114114 private var sessions: List <DialogSession > = emptyList()
115115
116+ private var attached = false
117+
118+ private var earlyUpdate: Pair <List <Overlay >, ViewEnvironment > ? = null
119+
116120 public var allowEvents: Boolean = true
117121 private set(value) {
118122 val was = field
@@ -140,6 +144,12 @@ public class LayeredDialogSessions private constructor(
140144 viewEnvironment : ViewEnvironment ,
141145 updateBase : (environment: ViewEnvironment ) -> Unit
142146 ) {
147+ if (! attached) {
148+ earlyUpdate = Pair (overlays, viewEnvironment)
149+ updateBase(viewEnvironment)
150+ return
151+ }
152+
143153 // Set up a ViewEnvironment with the single DialogCollator instance that handles
144154 // this entire view hierarchy. See that class for details.
145155 val envWithDialogManager =
@@ -201,10 +211,15 @@ public class LayeredDialogSessions private constructor(
201211 savedStateParentKey : String ,
202212 view : View
203213 ) {
214+ attached = true
204215 stateRegistryAggregator.attachToParentRegistry(
205216 savedStateParentKey,
206217 WorkflowAndroidXSupport .stateRegistryOwnerFromViewTreeOrContext(view)
207218 )
219+ earlyUpdate?.let { update ->
220+ earlyUpdate = null
221+ update(update.first, update.second) { /* Base was already updated. */ }
222+ }
208223 }
209224
210225 /* *
@@ -213,6 +228,7 @@ public class LayeredDialogSessions private constructor(
213228 * Must be matched with a call to [onAttachedToWindow].
214229 */
215230 public fun onDetachedFromWindow () {
231+ attached = false
216232 stateRegistryAggregator.detachFromParentRegistry()
217233 }
218234
0 commit comments