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
Fixes#597.
It used to be the case that every `DecorativeViewFactory` called
`showRendering()` twice (#397). We fixed that (we thought) by introducing the
`initializeView` lambda to `ViewRegistry.buildView` and
`DecorativeViewFactory` (#408).
Unfortunately, that fix botched recursion. Individual `DecorativeViewFactory`
instances work fine, but if you wrap them you still get one `showRendering`
call from each. Worse, upstream `initializeView` lambdas are clobbered by
immediately downstream ones. e.g., when a `WorkflowViewStub` shows a
`DecorativeViewFactory`, the `WorkflowLifecycleRunner.installOn` call in the
former is clobbered.
The fix is to completely decouple building a view from from this kind of
initialization. `ViewRegistry.buildView` and its wrappers no longer try to
call `showRendering` at all.
Instead the caller of `buildView` (mostly `WorkflowViewStub`) is reponsible
for immediately calling `View.start` on the new `View`. `View.start` makes
the initial `showRendering` call that formerly was the job of
`ViewFactory.buildView` -- the factory builds the view, and the container
turns the key. Since `View.start` is called only after all wrapped
`ViewFactory.buildView` functions have executed, we're certain it will only
happen once.
Of course we still need the ability to customize view initialization via
wrapping, especially to invoke `WorkflowLifecycleOwner.installOn`. To
accomodate that, the function that `View.start` executes can be wrapped via
the new `viewStarter` argument to `ViewRegistry.buildView` and
`DecorativeViewFactory`, which replaces `initializeView`.
This required a pretty thorough overhaul of `ViewShowRendering.kt`, which is
renamed `WorkflowUiViewState.kt`. `WorkflowUiViewState` is a sealed class
that hangs off of a view tag, with two implementations (`New` and `Started`)
to help us enforce the order of the `ViewRegistry.buildView`,
`View.bindShowRendering`, `View.start` and `View.showRendering` calls.
Copy file name to clipboardExpand all lines: workflow-ui/core-android/api/core-android.api
+53-29Lines changed: 53 additions & 29 deletions
Original file line number
Diff line number
Diff line change
@@ -24,10 +24,10 @@ public final class com/squareup/workflow1/ui/BuilderViewFactory : com/squareup/w
24
24
}
25
25
26
26
public final class com/squareup/workflow1/ui/DecorativeViewFactory : com/squareup/workflow1/ui/ViewFactory {
27
-
public fun <init> (Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function4;)V
28
-
public synthetic fun <init> (Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function4;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
29
-
public fun <init> (Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function4;)V
30
-
public synthetic fun <init> (Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function4;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
27
+
public fun <init> (Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow1/ui/ViewStarter;Lkotlin/jvm/functions/Function4;)V
28
+
public synthetic fun <init> (Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow1/ui/ViewStarter;Lkotlin/jvm/functions/Function4;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
29
+
public fun <init> (Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function2;Lcom/squareup/workflow1/ui/ViewStarter;Lkotlin/jvm/functions/Function4;)V
30
+
public synthetic fun <init> (Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function2;Lcom/squareup/workflow1/ui/ViewStarter;Lkotlin/jvm/functions/Function4;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
31
31
public fun buildView (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View;
32
32
public fun getType ()Lkotlin/reflect/KClass;
33
33
}
@@ -51,21 +51,6 @@ public final class com/squareup/workflow1/ui/LayoutRunnerViewFactory : com/squar
51
51
public fun getType ()Lkotlin/reflect/KClass;
52
52
}
53
53
54
-
public final class com/squareup/workflow1/ui/ShowRenderingTag {
55
-
public fun <init> (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function2;)V
56
-
public final fun component1 ()Ljava/lang/Object;
57
-
public final fun component2 ()Lcom/squareup/workflow1/ui/ViewEnvironment;
58
-
public final fun component3 ()Lkotlin/jvm/functions/Function2;
59
-
public final fun copy (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function2;)Lcom/squareup/workflow1/ui/ShowRenderingTag;
60
-
public static synthetic fun copy$default (Lcom/squareup/workflow1/ui/ShowRenderingTag;Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lcom/squareup/workflow1/ui/ShowRenderingTag;
61
-
public fun equals (Ljava/lang/Object;)Z
62
-
public final fun getEnvironment ()Lcom/squareup/workflow1/ui/ViewEnvironment;
63
-
public final fun getShowRendering ()Lkotlin/jvm/functions/Function2;
64
-
public final fun getShowing ()Ljava/lang/Object;
65
-
public fun hashCode ()I
66
-
public fun toString ()Ljava/lang/String;
67
-
}
68
-
69
54
public final class com/squareup/workflow1/ui/SnapshotParcelsKt {
70
55
public static final fun toSnapshot (Landroid/os/Parcelable;)Lcom/squareup/workflow1/Snapshot;
71
56
}
@@ -124,21 +109,15 @@ public final class com/squareup/workflow1/ui/ViewRegistry$Companion : com/square
124
109
public final class com/squareup/workflow1/ui/ViewRegistryKt {
125
110
public static final fun ViewRegistry ()Lcom/squareup/workflow1/ui/ViewRegistry;
126
111
public static final fun ViewRegistry ([Lcom/squareup/workflow1/ui/ViewFactory;)Lcom/squareup/workflow1/ui/ViewRegistry;
127
-
public static final fun buildView (Lcom/squareup/workflow1/ui/ViewRegistry;Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;Lkotlin/jvm/functions/Function1;)Landroid/view/View;
128
-
public static synthetic fun buildView$default (Lcom/squareup/workflow1/ui/ViewRegistry;Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Landroid/view/View;
112
+
public static final fun buildView (Lcom/squareup/workflow1/ui/ViewRegistry;Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;Lcom/squareup/workflow1/ui/ViewStarter;)Landroid/view/View;
113
+
public static synthetic fun buildView$default (Lcom/squareup/workflow1/ui/ViewRegistry;Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;Lcom/squareup/workflow1/ui/ViewStarter;ILjava/lang/Object;)Landroid/view/View;
129
114
public static final fun getFactoryForRendering (Lcom/squareup/workflow1/ui/ViewRegistry;Ljava/lang/Object;)Lcom/squareup/workflow1/ui/ViewFactory;
130
115
public static final fun plus (Lcom/squareup/workflow1/ui/ViewRegistry;Lcom/squareup/workflow1/ui/ViewFactory;)Lcom/squareup/workflow1/ui/ViewRegistry;
131
116
public static final fun plus (Lcom/squareup/workflow1/ui/ViewRegistry;Lcom/squareup/workflow1/ui/ViewRegistry;)Lcom/squareup/workflow1/ui/ViewRegistry;
132
-
public static final fun showFirstRendering (Landroid/view/View;)V
133
117
}
134
118
135
-
public final class com/squareup/workflow1/ui/ViewShowRenderingKt {
136
-
public static final fun bindShowRendering (Landroid/view/View;Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function2;)V
137
-
public static final fun canShowRendering (Landroid/view/View;Ljava/lang/Object;)Z
138
-
public static final fun getEnvironment (Landroid/view/View;)Lcom/squareup/workflow1/ui/ViewEnvironment;
139
-
public static final fun getRendering (Landroid/view/View;)Ljava/lang/Object;
140
-
public static final fun getShowRendering (Landroid/view/View;)Lkotlin/jvm/functions/Function2;
141
-
public static final fun showRendering (Landroid/view/View;Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;)V
119
+
public abstract interface class com/squareup/workflow1/ui/ViewStarter {
120
+
public abstract fun startView (Landroid/view/View;Lkotlin/jvm/functions/Function0;)V
142
121
}
143
122
144
123
public final class com/squareup/workflow1/ui/WorkflowLayout : android/widget/FrameLayout {
@@ -149,6 +128,51 @@ public final class com/squareup/workflow1/ui/WorkflowLayout : android/widget/Fra
149
128
public static synthetic fun start$default (Lcom/squareup/workflow1/ui/WorkflowLayout;Lkotlinx/coroutines/flow/Flow;Lcom/squareup/workflow1/ui/ViewEnvironment;ILjava/lang/Object;)V
150
129
}
151
130
131
+
public abstract class com/squareup/workflow1/ui/WorkflowUiViewState {
132
+
public abstract fun getEnvironment ()Lcom/squareup/workflow1/ui/ViewEnvironment;
133
+
public abstract fun getShowRendering ()Lkotlin/jvm/functions/Function2;
134
+
}
135
+
136
+
public final class com/squareup/workflow1/ui/WorkflowUiViewState$New : com/squareup/workflow1/ui/WorkflowUiViewState {
137
+
public fun <init> (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)V
138
+
public synthetic fun <init> (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
139
+
public final fun component2 ()Lcom/squareup/workflow1/ui/ViewEnvironment;
140
+
public final fun component3 ()Lkotlin/jvm/functions/Function2;
141
+
public final fun component4 ()Lkotlin/jvm/functions/Function1;
142
+
public final fun copy (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)Lcom/squareup/workflow1/ui/WorkflowUiViewState$New;
143
+
public static synthetic fun copy$default (Lcom/squareup/workflow1/ui/WorkflowUiViewState$New;Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/squareup/workflow1/ui/WorkflowUiViewState$New;
144
+
public fun equals (Ljava/lang/Object;)Z
145
+
public fun getEnvironment ()Lcom/squareup/workflow1/ui/ViewEnvironment;
146
+
public fun getShowRendering ()Lkotlin/jvm/functions/Function2;
147
+
public synthetic fun getShowing ()Ljava/lang/Object;
148
+
public final fun getStarter ()Lkotlin/jvm/functions/Function1;
149
+
public fun hashCode ()I
150
+
public fun toString ()Ljava/lang/String;
151
+
}
152
+
153
+
public final class com/squareup/workflow1/ui/WorkflowUiViewState$Started : com/squareup/workflow1/ui/WorkflowUiViewState {
154
+
public fun <init> (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function2;)V
155
+
public final fun component2 ()Lcom/squareup/workflow1/ui/ViewEnvironment;
156
+
public final fun component3 ()Lkotlin/jvm/functions/Function2;
157
+
public final fun copy (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function2;)Lcom/squareup/workflow1/ui/WorkflowUiViewState$Started;
158
+
public static synthetic fun copy$default (Lcom/squareup/workflow1/ui/WorkflowUiViewState$Started;Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lcom/squareup/workflow1/ui/WorkflowUiViewState$Started;
159
+
public fun equals (Ljava/lang/Object;)Z
160
+
public fun getEnvironment ()Lcom/squareup/workflow1/ui/ViewEnvironment;
161
+
public fun getShowRendering ()Lkotlin/jvm/functions/Function2;
162
+
public synthetic fun getShowing ()Ljava/lang/Object;
163
+
public fun hashCode ()I
164
+
public fun toString ()Ljava/lang/String;
165
+
}
166
+
167
+
public final class com/squareup/workflow1/ui/WorkflowUiViewStateKt {
168
+
public static final fun bindShowRendering (Landroid/view/View;Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function2;)V
169
+
public static final fun canShowRendering (Landroid/view/View;Ljava/lang/Object;)Z
170
+
public static final fun getEnvironment (Landroid/view/View;)Lcom/squareup/workflow1/ui/ViewEnvironment;
171
+
public static final fun getShowRendering (Landroid/view/View;)Lkotlin/jvm/functions/Function2;
172
+
public static final fun showRendering (Landroid/view/View;Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;)V
173
+
public static final fun start (Landroid/view/View;)V
174
+
}
175
+
152
176
public final class com/squareup/workflow1/ui/WorkflowViewStub : android/view/View {
153
177
public fun <init> (Landroid/content/Context;)V
154
178
public fun <init> (Landroid/content/Context;Landroid/util/AttributeSet;)V
0 commit comments