33package com.squareup.workflow1.internal
44
55import 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
116import androidx.compose.runtime.currentCompositeKeyHash
127import androidx.compose.runtime.currentCompositionLocalContext
138import androidx.compose.runtime.currentRecomposeScope
14- import androidx.compose.runtime.mutableStateOf
159import androidx.compose.runtime.remember
1610import androidx.compose.runtime.rememberCoroutineScope
17- import androidx.compose.runtime.saveable.LocalSaveableStateRegistry
18- import androidx.compose.runtime.saveable.SaveableStateRegistry
1911import com.squareup.workflow1.ActionApplied
2012import com.squareup.workflow1.ActionProcessingResult
2113import com.squareup.workflow1.NoopWorkflowInterceptor
@@ -27,16 +19,11 @@ import com.squareup.workflow1.WorkflowExperimentalApi
2719import com.squareup.workflow1.WorkflowInterceptor
2820import com.squareup.workflow1.WorkflowInterceptor.WorkflowSession
2921import com.squareup.workflow1.WorkflowTracer
30- import com.squareup.workflow1.compose.LocalWorkflowCompositionHost
3122import com.squareup.workflow1.compose.WorkflowCompositionHost
3223import com.squareup.workflow1.identifier
3324import com.squareup.workflow1.trace
34- import kotlinx.coroutines.CoroutineScope
35- import kotlinx.coroutines.CoroutineStart
36- import kotlinx.coroutines.launch
3725import kotlinx.coroutines.selects.SelectBuilder
3826import kotlin.coroutines.CoroutineContext
39- import kotlin.coroutines.EmptyCoroutineContext
4027
4128/* *
4229 * Responsible for tracking child workflows, starting them and tearing them down when necessary.
@@ -171,50 +158,15 @@ internal class SubtreeManager<PropsT, StateT, OutputT>(
171158 key : String ,
172159 content : @Composable () -> ChildRenderingT
173160 ): 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()
215168
216- @Suppress(" UNCHECKED_CAST" )
217- return rendering.value as ChildRenderingT
169+ node.render(content)
218170 }
219171
220172 @Composable
0 commit comments