3
3
package com.squareup.workflow1.internal
4
4
5
5
import androidx.compose.runtime.Composable
6
- import androidx.compose.runtime.Composition
7
- import androidx.compose.runtime.CompositionLocalContext
8
- import androidx.compose.runtime.CompositionLocalProvider
9
- import androidx.compose.runtime.MonotonicFrameClock
10
- import androidx.compose.runtime.Recomposer
11
6
import androidx.compose.runtime.currentCompositeKeyHash
12
7
import androidx.compose.runtime.currentCompositionLocalContext
13
8
import androidx.compose.runtime.currentRecomposeScope
14
- import androidx.compose.runtime.mutableStateOf
15
9
import androidx.compose.runtime.remember
16
10
import androidx.compose.runtime.rememberCoroutineScope
17
- import androidx.compose.runtime.saveable.LocalSaveableStateRegistry
18
- import androidx.compose.runtime.saveable.SaveableStateRegistry
19
11
import com.squareup.workflow1.ActionApplied
20
12
import com.squareup.workflow1.ActionProcessingResult
21
13
import com.squareup.workflow1.NoopWorkflowInterceptor
@@ -27,16 +19,11 @@ import com.squareup.workflow1.WorkflowExperimentalApi
27
19
import com.squareup.workflow1.WorkflowInterceptor
28
20
import com.squareup.workflow1.WorkflowInterceptor.WorkflowSession
29
21
import com.squareup.workflow1.WorkflowTracer
30
- import com.squareup.workflow1.compose.LocalWorkflowCompositionHost
31
22
import com.squareup.workflow1.compose.WorkflowCompositionHost
32
23
import com.squareup.workflow1.identifier
33
24
import com.squareup.workflow1.trace
34
- import kotlinx.coroutines.CoroutineScope
35
- import kotlinx.coroutines.CoroutineStart
36
- import kotlinx.coroutines.launch
37
25
import kotlinx.coroutines.selects.SelectBuilder
38
26
import kotlin.coroutines.CoroutineContext
39
- import kotlin.coroutines.EmptyCoroutineContext
40
27
41
28
/* *
42
29
* Responsible for tracking child workflows, starting them and tearing them down when necessary.
@@ -171,50 +158,15 @@ internal class SubtreeManager<PropsT, StateT, OutputT>(
171
158
key : String ,
172
159
content : @Composable () -> ChildRenderingT
173
160
): ChildRenderingT {
174
- val frameClock: MonotonicFrameClock // TODO
175
- val coroutineContext = EmptyCoroutineContext + frameClock
176
- val recomposer = Recomposer (coroutineContext)
177
- val composition = Composition (UnitApplier , recomposer)
178
- val saveableStateRegistry: SaveableStateRegistry // TODO
179
- val localsContext: CompositionLocalContext ? // TODO
180
-
181
- // TODO I think we need more than a simple UNDISPATCHED start to make this work – we have to
182
- // pump the dispatcher until the composition is finished.
183
- CoroutineScope (coroutineContext).launch(start = CoroutineStart .UNDISPATCHED ) {
184
- try {
185
- recomposer.runRecomposeAndApplyChanges()
186
- } finally {
187
- composition.dispose()
188
- }
189
- }
190
-
191
- val rendering = mutableStateOf<ChildRenderingT ?>(null )
192
- val wrappedContent = @Composable {
193
- CompositionLocalProvider (
194
- LocalWorkflowCompositionHost provides this ,
195
- LocalSaveableStateRegistry provides saveableStateRegistry,
196
- ) {
197
- rendering.value = content()
198
- }
199
- }
200
-
201
- composition.setContent {
202
- // Must provide the locals from the parent composition first so we can override the ones we
203
- // need. If it's null then there's no parent, but the CompositionLocalProvider API has no nice
204
- // way to pass nothing in this overload. I believe it's safe to actually call content through
205
- // two different code paths because whether there's a parent composition cannot change for an
206
- // existing workflow session – they can't move.
207
- if (localsContext == null ) {
208
- wrappedContent()
209
- } else {
210
- CompositionLocalProvider (localsContext, wrappedContent)
211
- }
212
- }
213
-
214
- // TODO prime the first frame to generate the initial rendering
161
+ // TODO initialize, store, and start the node from an ActiveStagingList
162
+ val node = WorkflowComposableNode <ChildRenderingT >(
163
+ frameClock = TODO (),
164
+ saveableStateRegistry = TODO (),
165
+ localsContext = TODO (" get from parent somehow" )
166
+ )
167
+ node.start()
215
168
216
- @Suppress(" UNCHECKED_CAST" )
217
- return rendering.value as ChildRenderingT
169
+ node.render(content)
218
170
}
219
171
220
172
@Composable
0 commit comments