Skip to content

Commit 5fd5d47

Browse files
committed
wip: do not build dialogs before container is attached, still needs tests at the very least
1 parent e5c7ff9 commit 5fd5d47

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/container/LayeredDialogSessions.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)