Skip to content

Commit 10e1725

Browse files
Temp commit for broken compose test
1 parent 2830e96 commit 10e1725

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/launcher/SampleLauncherTest.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.squareup.sample.compose.launcher
22

3-
import androidx.compose.ui.test.ExperimentalTestApi
43
import androidx.compose.ui.test.assertIsDisplayed
54
import androidx.compose.ui.test.hasScrollToIndexAction
65
import androidx.compose.ui.test.junit4.createAndroidComposeRule
@@ -31,7 +30,6 @@ class SampleLauncherTest {
3130
.around(composeRule)
3231
.around(IdlingDispatcherRule)
3332

34-
@OptIn(ExperimentalTestApi::class)
3533
@Test
3634
fun allSamplesLaunch() {
3735
val appName =

samples/compose-samples/src/main/java/com/squareup/sample/compose/inlinerendering/InlineRenderingWorkflow.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import androidx.compose.animation.slideOutVertically
1212
import androidx.compose.animation.with
1313
import androidx.compose.foundation.layout.Box
1414
import androidx.compose.material.Button
15+
import androidx.compose.material.MaterialTheme
1516
import androidx.compose.material.Text
1617
import androidx.compose.runtime.Composable
1718
import androidx.compose.runtime.getValue
@@ -53,9 +54,8 @@ object InlineRenderingWorkflow : StatefulWorkflow<Unit, Int, Nothing, AndroidScr
5354
override fun snapshotState(state: Int): Snapshot = Snapshot.of(state)
5455
}
5556

56-
@Preview
5757
@Composable
58-
fun InlineRenderingWorkflowPreview() {
58+
fun InlineRenderingWorkflowRendering() {
5959
val rendering by InlineRenderingWorkflow.renderAsState(
6060
props = Unit,
6161
onOutput = {},
@@ -64,6 +64,12 @@ fun InlineRenderingWorkflowPreview() {
6464
WorkflowRendering(rendering, ViewEnvironment.EMPTY)
6565
}
6666

67+
@Preview(showBackground = true)
68+
@Composable
69+
internal fun InlineRenderingWorkflowPreview() {
70+
InlineRenderingWorkflowRendering()
71+
}
72+
6773
@OptIn(ExperimentalAnimationApi::class)
6874
@Composable
6975
private fun AnimatedCounter(

workflow-ui/compose/src/main/java/com/squareup/workflow1/ui/compose/RenderAsState.kt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ import com.squareup.workflow1.WorkflowInterceptor
2323
import com.squareup.workflow1.renderWorkflowIn
2424
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
2525
import kotlinx.coroutines.CoroutineScope
26+
import kotlinx.coroutines.CoroutineStart.UNDISPATCHED
2627
import kotlinx.coroutines.Dispatchers
2728
import kotlinx.coroutines.Job
2829
import kotlinx.coroutines.cancel
2930
import kotlinx.coroutines.flow.MutableStateFlow
3031
import kotlinx.coroutines.flow.launchIn
3132
import kotlinx.coroutines.flow.onEach
33+
import kotlinx.coroutines.launch
3234
import kotlinx.coroutines.plus
3335
import okio.ByteString
3436

@@ -206,18 +208,23 @@ private class WorkflowRuntimeState<PropsT, OutputT : Any, RenderingT>(
206208
onOutput = onOutput
207209
)
208210

209-
renderings
210-
.onEach {
211-
renderingState.value = it.rendering
212-
snapshotState.value = it.snapshot
213-
}
211+
workflowScope.launch(
212+
start = UNDISPATCHED,
213+
context = Dispatchers.Unconfined
214+
) {
214215
// We collect the renderings in the workflowScope to participate in structured concurrency,
215216
// however we don't need to use its dispatcher – this collector is simply setting snapshot
216217
// state values, which is thread safe.
217218
// Also, if the scope uses a non-immediate dispatcher, the initial states won't get set until
218219
// the dispatcher dispatches the collection coroutine, but our contract requires them to be
219-
// set by the time this function returns and using the Unconfined dispatcher guarantees that.
220-
.launchIn(workflowScope + Dispatchers.Unconfined)
220+
// set by the time this function returns and using the Unconfined dispatcher along with
221+
// launching this coroutine as CoroutineStart.UNDISPATCHED guarantees that.
222+
223+
renderings.collect {
224+
renderingState.value = it.rendering
225+
snapshotState.value = it.snapshot
226+
}
227+
}
221228
}
222229

223230
fun setProps(props: PropsT) {

0 commit comments

Comments
 (0)