You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. `setContent` as a method name gave no clue that we were returning a new manager object, so now it's called `asDialogHolderWithContent`
2. Hard coding the call to `Dialog.setContent` interferes with code that needs to make that call itself. We now accept a `setContent: (ScreenViewHolder<C>) -> Unit` lambda to do that work, which defaults to the current behavior.
3. Decouple building and starting views. This allows us to ensure that a Dialog's content view is attached to its window before its first rendering -- before the first call to `ScreenViewHolder.show`. Necessary to ensure that the strictly view-tree-based AndroidX `findViewTreeOnBackPressedDispatcherOwner()` call works immediately. This was always the original intention, but never actually found a use case until now.
4. Moves most of that default behavior to a public `Dialog.fixBackgroundAndDimming` extension function to keep it available and more self documenting (hard learned lessons in there). Pretty similar to how `ScreenOverlayDialogFactory` acts.
5. Big kdoc update
Copy file name to clipboardExpand all lines: workflow-ui/compose/src/androidTest/java/com/squareup/workflow1/ui/compose/ComposeViewTreeIntegrationTest.kt
Copy file name to clipboardExpand all lines: workflow-ui/core-android/api/core-android.api
+9-5Lines changed: 9 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -129,6 +129,7 @@ public final class com/squareup/workflow1/ui/ScreenViewFactoryFinder$DefaultImpl
129
129
130
130
public final class com/squareup/workflow1/ui/ScreenViewFactoryKt {
131
131
public static final fun startShowing (Lcom/squareup/workflow1/ui/ScreenViewFactory;Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;Lcom/squareup/workflow1/ui/ViewStarter;)Lcom/squareup/workflow1/ui/ScreenViewHolder;
132
+
public static final fun startShowing (Lcom/squareup/workflow1/ui/ScreenViewHolder;Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;Lcom/squareup/workflow1/ui/ViewStarter;)V
132
133
public static synthetic fun startShowing$default (Lcom/squareup/workflow1/ui/ScreenViewFactory;Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;Lcom/squareup/workflow1/ui/ViewStarter;ILjava/lang/Object;)Lcom/squareup/workflow1/ui/ScreenViewHolder;
133
134
public static final fun toViewFactory (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;)Lcom/squareup/workflow1/ui/ScreenViewFactory;
134
135
}
@@ -306,7 +307,8 @@ public final class com/squareup/workflow1/ui/androidx/WorkflowSavedStateRegistry
306
307
public fun <init> ()V
307
308
public final fun attachToParentRegistry (Ljava/lang/String;Landroidx/savedstate/SavedStateRegistryOwner;)V
308
309
public final fun detachFromParentRegistry ()V
309
-
public final fun installChildRegistryOwnerOn (Landroid/view/View;Ljava/lang/String;)V
310
+
public final fun installChildRegistryOwnerOn (Landroid/view/View;Ljava/lang/String;Z)V
311
+
public static synthetic fun installChildRegistryOwnerOn$default (Lcom/squareup/workflow1/ui/androidx/WorkflowSavedStateRegistryAggregator;Landroid/view/View;Ljava/lang/String;ZILjava/lang/Object;)V
310
312
public final fun pruneAllChildRegistryOwnersExcept (Ljava/util/Collection;)V
311
313
public static synthetic fun pruneAllChildRegistryOwnersExcept$default (Lcom/squareup/workflow1/ui/androidx/WorkflowSavedStateRegistryAggregator;Ljava/util/Collection;ILjava/lang/Object;)V
312
314
public final fun saveAndPruneChildRegistryOwner (Ljava/lang/String;)V
@@ -331,6 +333,12 @@ public abstract interface class com/squareup/workflow1/ui/container/AndroidOverl
331
333
public abstract fun getDialogFactory ()Lcom/squareup/workflow1/ui/container/OverlayDialogFactory;
332
334
}
333
335
336
+
public final class com/squareup/workflow1/ui/container/AsDialogHolderWithContentKt {
337
+
public static final fun asDialogHolderWithContent (Landroidx/activity/ComponentDialog;Lcom/squareup/workflow1/ui/container/ScreenOverlay;Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function1;)Lcom/squareup/workflow1/ui/container/OverlayDialogHolder;
338
+
public static synthetic fun asDialogHolderWithContent$default (Landroidx/activity/ComponentDialog;Lcom/squareup/workflow1/ui/container/ScreenOverlay;Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/squareup/workflow1/ui/container/OverlayDialogHolder;
339
+
public static final fun fixBackgroundAndDimming (Landroid/app/Dialog;)V
340
+
}
341
+
334
342
public final class com/squareup/workflow1/ui/container/BackButtonScreen : com/squareup/workflow1/ui/AndroidScreen, com/squareup/workflow1/ui/Wrapper {
335
343
public fun <init> (Lcom/squareup/workflow1/ui/Screen;ZLkotlin/jvm/functions/Function0;)V
336
344
public synthetic fun <init> (Lcom/squareup/workflow1/ui/Screen;ZLkotlin/jvm/functions/Function0;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
@@ -376,10 +384,6 @@ public final class com/squareup/workflow1/ui/container/BackStackContainer$SavedS
376
384
public synthetic fun newArray (I)[Ljava/lang/Object;
377
385
}
378
386
379
-
public final class com/squareup/workflow1/ui/container/ComponentDialogSetContentKt {
380
-
public static final fun setContent (Landroidx/activity/ComponentDialog;Lcom/squareup/workflow1/ui/container/ScreenOverlay;Lcom/squareup/workflow1/ui/ViewEnvironment;)Lcom/squareup/workflow1/ui/container/OverlayDialogHolder;
381
-
}
382
-
383
387
public final class com/squareup/workflow1/ui/container/LayeredDialogSessions {
384
388
public static final field Companion Lcom/squareup/workflow1/ui/container/LayeredDialogSessions$Companion;
385
389
public synthetic fun <init> (Landroid/content/Context;Lkotlinx/coroutines/flow/StateFlow;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
Copy file name to clipboardExpand all lines: workflow-ui/core-android/src/androidTest/java/com/squareup/workflow1/ui/container/DialogIntegrationTest.kt
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -66,7 +66,7 @@ internal class DialogIntegrationTest {
66
66
67
67
overrideval dialogFactory =OverlayDialogFactory<DialogRendering> { r, e, c ->
68
68
val dialog =ComponentDialog(c).also { latestDialog = it }
Copy file name to clipboardExpand all lines: workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/androidx/WorkflowSavedStateRegistryAggregator.kt
+16-4Lines changed: 16 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -211,10 +211,18 @@ public class WorkflowSavedStateRegistryAggregator {
211
211
* [WorkflowSavedStateRegistryAggregator]. Typically this is derived from the
212
212
* [compatibility key][com.squareup.workflow1.ui.Compatible.keyFor] of the [view]'s
213
213
* rendering.
214
+
*
215
+
* @param force when this is true we're asserting that it's okay to clobber an
216
+
* existing registry that may have been put in place by Android. If we find
217
+
* one of our own [KeyedSavedStateRegistryOwner], we will still throw an exception.
218
+
*
219
+
* @throws IllegalArgumentException is [key] is already in use or if [view] has an
220
+
* unexpected [SavedStateRegistryOwner] in place already.
214
221
*/
215
222
publicfuninstallChildRegistryOwnerOn(
216
223
view:View,
217
-
key:String
224
+
key:String,
225
+
force:Boolean = false
218
226
) {
219
227
val lifecycleOwner = requireNotNull(ViewTreeLifecycleOwner.get(view)) {
220
228
"Expected $view($key) to have a ViewTreeLifecycleOwner. "+
@@ -224,9 +232,13 @@ public class WorkflowSavedStateRegistryAggregator {
224
232
children.put(key, registryOwner)?.let {
225
233
throwIllegalArgumentException("$key is already in use, it cannot be used to register $view")
226
234
}
227
-
view.findViewTreeSavedStateRegistryOwner()?.let {
228
-
throwIllegalArgumentException("$view already has SavedStateRegistryOwner: $it")
229
-
}
235
+
view.findViewTreeSavedStateRegistryOwner()
236
+
?.takeIf { !force || it isKeyedSavedStateRegistryOwner }
237
+
?.let {
238
+
throwIllegalArgumentException(
239
+
"Using $key to register $view, but it already has SavedStateRegistryOwner: $it"
0 commit comments