JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.27k stars 1.11k forks source link

kotlin.IllegalStateException: ComposeScene is closed for Popup on iOS #4916

Closed syru88 closed 3 weeks ago

syru88 commented 4 weeks ago

Describe the bug When Popup on iOS is opened and closed after short period of time (milliseconds), kotlin.IllegalStateException: ComposeScene is closed is thrown.

Affected platforms

Versions

To Reproduce Steps to reproduce the behavior:

  1. Checkout code from https://github.com/syru88/PopupCrash or use this snippet:

    
    @Composable
    @Preview
    fun App() {
    MaterialTheme {
        var showContent by remember { mutableStateOf(false) }
    
        if (showContent) {
            LoadingHud()
        }
    
        val coroutineScope = rememberCoroutineScope()
        Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
            Button(onClick = {
                showContent = true
                coroutineScope.launch {
                    // no crash when delay is 50ms or more
                    delay(10.milliseconds)
                    showContent = false
                }
            }) {
                Text("Click me!")
            }
        }
    }
    }

@Composable fun LoadingHud() { Popup { Box( modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center, ) { Column( modifier = Modifier .requiredWidth(150.dp) .wrapContentHeight() .background( color = Color.Gray.copy(alpha = 0.7f), shape = RoundedCornerShape(12.dp) ) .padding(horizontal = 16.dp, vertical = 24.dp), horizontalAlignment = Alignment.CenterHorizontally, ) { CircularProgressIndicator(modifier = Modifier.size(48.dp).padding(8.dp)) Spacer(Modifier.height(8.dp)) Text("Popup") }

    }
}

}


2. Click on 'Click me'
3. See error

**Expected behavior**
No crash should happen. It's working on Android or when longer delay is used (60ms).
MatkovIvan commented 3 weeks ago

Fixed by https://github.com/JetBrains/compose-multiplatform-core/pull/1384

liufeng382641424 commented 1 week ago

@MatkovIvan This problem has not been fixed in version 1.6.11. I call the Dialog to display and close it in milliseconds, but it still behaves abnormally. In addition, I have not found a way to modify the semi-transparent background of the Dialog. Can you tell me? Thank you, brother.

MatkovIvan commented 1 week ago

This problem has not been fixed in version 1.6.11.

It's not included to this version

I have not found a way to modify the semi-transparent background of the Dialog

There is no common way to do that. For Multiplatform/non-Android you can use DialogProperties.scrimColor for that

liufeng382641424 commented 1 week ago

@MatkovIvan Thanks, can you tell me which version has been fixed? I encountered a similar bug in iPhone 6s and iPhone 7Plus, and I don't know how to fix it. After entering text in the input box, I keep double-clicking the input box. At this time, a copy prompt box will pop up. If I keep double-clicking the prompt box, it will keep appearing and closing. At this time, it will also crash. The exception is also the same. I feel that it is the same bug, right?

MatkovIvan commented 1 week ago

Thanks, can you tell me which version has been fixed?

It will be part of 1.7.0

I feel that it is the same bug, right?

It sounds so

liufeng382641424 commented 1 week ago

@MatkovIvan There are 2 input boxes on a page. I enter text in one of them and double-click to pop up the copy prompt box. At this time, clicking the other input box will cause an abnormality. I would like to ask if there is any preventive solution at present? In addition, when is 1.7.0 expected to be released?

liufeng382641424 commented 1 week ago

@MatkovIvan Or can I disable the copy function of the input box? Thanks bro

MatkovIvan commented 1 week ago

There are 2 input boxes on a page. I enter text in one of them and double-click to pop up the copy prompt box. At this time, clicking the other input box will cause an abnormality. I would like to ask if there is any preventive solution at present?

Sorry, it's not clear what "abnormality" is. It doesn't seem related to the topic. If you think that it's some problem that should bt fixed - please open separate issue with full description and repro

In addition, when is 1.7.0 expected to be released?

From docs: "The gap between a Compose Multiplatform release and a Jetpack Compose release is usually 1–3 months."

Or can I disable the copy function of the input box?

3286