Status Update
Comments
ti...@google.com <ti...@google.com>
as...@google.com <as...@google.com> #2
Does the program work without the compiler switch. That is, is `"-P", "plugin:androidx.compose.compiler.plugins.kotlin:experimentalStrongSkipping=true",` required to reproduce or is just changing the runtime enough?
ms...@hubspot.com <ms...@hubspot.com> #3
Sorry for that, I will try to extract an example when I'm free.
bl...@gmail.com <bl...@gmail.com> #4
I have find a sample code to reproduce that
setContent {
val dialogState = remember { DialogState() }
dialogState.Intercept()
LaunchedEffect(Unit) {
delay(1000)
dialogState.bgWork {
delay(5000)
}
dialogState.showSelectActions {
onSelect("a") {
}
onSelect("b") {
}
}
}
}
You can find implementation of DialogState
here
ms...@hubspot.com <ms...@hubspot.com> #5
Let me sort it out
The first crash
Reproduce: navigate to a gallery and navigate back
The reason is we have some code assume the forget order of RememberObserver(DisposableEffect), and 52835066c9044647a65dfb566f03131aab46e793
changed the order. Seems this is a intended behaviour.
I will fix it from my side. My bad
The second crash
Reproduce: #4 comment
StackTrace:
We got a wrong object from SlotTable during recompose
as...@google.com <as...@google.com> #6
And interestingly, if we insert delay(1000) between two dialog suspend usage
dialogState.bgWork {
delay(5000)
}
delay(1000)
dialogState.showSelectActions {
onSelect("a") {
}
onSelect("b") {
}
}
It will not crash
ms...@hubspot.com <ms...@hubspot.com> #7
As for the order of `onForgotten`, it may be you are seeing and issue that I fixed in a subsequent version as this, for the snapshot builds, was broken for a few weeks when using the non-skipping group optimization even indirectly.
ys...@google.com <ys...@google.com> #8
ap...@google.com <ap...@google.com> #9
I tried cutting down the example myself and was not able to reproduce this.
The primary dependency chagnes I made were:
compose-material3 = { module = "androidx.compose.material3:material3", version = "1.3.0-SNAPSHOT" }
compose-foundation = { module = "androidx.compose.foundation:foundation-android", version = "1.7.0-SNAPSHOT" }
I only included the part of the Dialog.kt that was needed by the above,
class DialogState {
var content: (@Composable () -> Unit)? by mutableStateOf(null)
@Composable
fun Intercept() = content?.invoke()
fun dismiss() {
content = null
}
suspend inline fun <R> dialog(crossinline block: @Composable (CancellableContinuation<R>) -> Unit) = suspendCancellableCoroutine<R> { cont ->
cont.invokeOnCancellation { dismiss() }
val realContinuation = object : CancellableContinuation<R> by cont {
override fun resumeWith(result: Result<R>) {
dismiss()
cont.resumeWith(result)
}
}
content = { block(realContinuation) }
}
suspend inline fun showSelectActions(
title: String? = null,
builder: ActionScope.() -> Unit,
) {
val (items, actions) = buildList { builder(ActionScope { action, that -> add(action to that) }) }.unzip()
val selected = showSelectItem(items, title)
actions[selected].invoke()
}
suspend fun showSelectItem(
items: List<String>,
title: String?,
respectDefaultWidth: Boolean = true,
): Int = showNoButton(respectDefaultWidth) {
Column(modifier = Modifier.padding(vertical = 8.dp)) {
if (title != null) {
Text(
text = title,
modifier = Modifier.padding(horizontal = 24.dp, vertical = 8.dp),
style = MaterialTheme.typography.headlineSmall,
)
}
LazyColumn {
itemsIndexed(items) { index, text ->
CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.tertiary) {
Text(
text = text,
modifier = Modifier.clickable { dismissWith(index) }.fillMaxWidth()
.padding(horizontal = 24.dp, vertical = 16.dp),
style = MaterialTheme.typography.titleMedium,
)
}
}
}
}
}
@OptIn(ExperimentalMaterial3Api::class)
suspend fun <R> showNoButton(respectDefaultWidth: Boolean = true, block: @Composable DismissDialogScope<R>.() -> Unit): R {
return dialog { cont ->
val impl = remember(cont) {
DismissDialogScope<R> {
cont.resume(it)
}
}
BasicAlertDialog(
onDismissRequest = { cont.cancel() },
properties = DialogProperties(usePlatformDefaultWidth = respectDefaultWidth),
content = {
Surface(
modifier = with(Modifier) { if (!respectDefaultWidth) defaultMinSize(280.dp) else width(280.dp) },
shape = AlertDialogDefaults.shape,
color = AlertDialogDefaults.containerColor,
tonalElevation = AlertDialogDefaults.TonalElevation,
content = { block(impl) },
)
},
)
}
}
}
fun interface ActionScope {
fun onSelect(action: String, that: suspend () -> Unit)
}
fun interface DismissDialogScope<R> {
fun dismissWith(value: R)
}
This shows the "Please wait" and then selection between "a" and "b" as I expected.
pr...@google.com <pr...@google.com> #10
This requires compose compiler 1.5.11-dev-k2.0.0-Beta4-21f5e479a96
I will upload a sample project soon
Description
Jetpack Compose component(s) used: compiler, ui, ui-test, ui-tooling
Android Studio Build:2023.2.1 Canary 14
Kotlin version:1.9.21
Steps to Reproduce or Code Sample to Reproduce:
We use paparazzi for screenshot testing, this is setup with a base test class which accepts a composable lambda.
Since updating compose-compiler, this function throws a ClassCastException
Stack trace (if applicable):
```
FullScreenPreviewTopBarScreenshotTest > testFullScreenPreviewTopBar[PIXEL_5_LIGHT_LARGE_FONT] FAILED
java.lang.ClassCastException: class androidx.compose.runtime.internal.ComposableLambdaImpl cannot be cast to class kotlin.jvm.functions.Function0 (androidx.compose.runtime.internal.ComposableLambdaImpl and kotlin.jvm.functions.Function0 are in unnamed module of loader 'app')
at com.x.android.files.preview.composables.FullScreenPreviewTopBarScreenshotTest.testFullScreenPreviewTopBar(FullScreenPreviewTopBarScreenshotTest.kt:10)
```
Test function
```
@Test
fun testFullScreenPreviewTopBar() =
runScreenshotTest {
FullScreenPreviewTopBarPreview()
}
```
Base class function
```
fun runScreenshotTest(content: @Composable () -> Unit) =
runTest(UnconfinedTestDispatcher()) {
paparazzi.snapshot {
CompositionLocalProvider(LocalInspectionMode provides true) {
CanvasTheme(
content = wrapInTestSurface(content),
darkTheme = config.deviceConfig.nightMode == NightMode.NIGHT,
)
}
}
}
```