@@ -2,15 +2,20 @@ package com.squareup.workflow1.internal.compose
2
2
3
3
import androidx.compose.runtime.Composable
4
4
import androidx.compose.runtime.DisposableEffect
5
+ import androidx.compose.runtime.NonRestartableComposable
6
+ import androidx.compose.runtime.ReadOnlyComposable
5
7
import androidx.compose.runtime.collection.MutableVector
6
8
import androidx.compose.runtime.currentRecomposeScope
7
9
import androidx.compose.runtime.getValue
8
10
import androidx.compose.runtime.key
11
+ import androidx.compose.runtime.mutableStateOf
9
12
import androidx.compose.runtime.remember
10
13
import androidx.compose.runtime.rememberCoroutineScope
11
14
import androidx.compose.runtime.rememberUpdatedState
12
15
import androidx.compose.runtime.saveable.LocalSaveableStateRegistry
13
16
import androidx.compose.runtime.saveable.SaveableStateRegistry
17
+ import androidx.compose.runtime.setValue
18
+ import androidx.compose.runtime.snapshots.Snapshot
14
19
import com.squareup.workflow1.ActionApplied
15
20
import com.squareup.workflow1.ActionProcessingResult
16
21
import com.squareup.workflow1.NoopWorkflowInterceptor
@@ -29,8 +34,8 @@ import com.squareup.workflow1.compose.WorkflowComposableRenderer
29
34
import com.squareup.workflow1.identifier
30
35
import com.squareup.workflow1.internal.IdCounter
31
36
import com.squareup.workflow1.internal.WorkflowNodeId
32
- import com.squareup.workflow1.internal.requireSend
33
37
import com.squareup.workflow1.internal.createId
38
+ import com.squareup.workflow1.internal.requireSend
34
39
import com.squareup.workflow1.workflowSessionToString
35
40
import kotlinx.coroutines.CoroutineName
36
41
import kotlinx.coroutines.CoroutineScope
@@ -96,6 +101,8 @@ internal class ComposeWorkflowChildNode<PropsT, OutputT, RenderingT>(
96
101
}
97
102
}
98
103
104
+ private var lastProps by mutableStateOf(initialProps)
105
+
99
106
/* *
100
107
* Function invoked when [onNextAction] receives an output from [outputsChannel].
101
108
*/
@@ -149,6 +156,9 @@ internal class ComposeWorkflowChildNode<PropsT, OutputT, RenderingT>(
149
156
// inside a renderChild call and renderChild does the keying.
150
157
log(" rendering workflow: props=$props " )
151
158
workflow as ComposeWorkflow
159
+
160
+ notifyInterceptorWhenPropsChanged(props)
161
+
152
162
return withCompositionLocals(
153
163
LocalSaveableStateRegistry provides saveableStateRegistry,
154
164
LocalWorkflowComposableRenderer provides this
@@ -167,6 +177,26 @@ internal class ComposeWorkflowChildNode<PropsT, OutputT, RenderingT>(
167
177
}
168
178
}
169
179
180
+ @ReadOnlyComposable
181
+ @NonRestartableComposable
182
+ @Composable
183
+ private fun notifyInterceptorWhenPropsChanged (newProps : PropsT ) {
184
+ // Don't both asking the composition to track reads of lastProps since this is the only function
185
+ // that will every write to it.
186
+ Snapshot .withoutReadObservation {
187
+ if (lastProps != newProps) {
188
+ interceptor.onPropsChanged(
189
+ old = lastProps,
190
+ new = newProps,
191
+ state = ComposeWorkflowState ,
192
+ session = this ,
193
+ proceed = { _, _, _ -> ComposeWorkflowState },
194
+ )
195
+ lastProps = newProps
196
+ }
197
+ }
198
+ }
199
+
170
200
@Composable
171
201
override fun <ChildPropsT , ChildOutputT , ChildRenderingT > renderChild (
172
202
childWorkflow : Workflow <ChildPropsT , ChildOutputT , ChildRenderingT >,
0 commit comments