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.63k stars 1.14k forks source link

UIKitView layout bug #3635

Open Khang-NT opened 11 months ago

Khang-NT commented 11 months ago

Describe the bug UIKitView displays behind another view within a Column, let's look at the screenshot, the text view on iPhone is behind the text box.

Screenshot 2023-09-07 at 10 45 00

Affected platforms Select one of the platforms below:

Versions

To Reproduce

// common
@Composable
fun Reproduce() {
    Column(Modifier.fillMaxWidth().padding(8.dp)) {
        Row {
            OutlinedTextField(
                value = "",
                onValueChange = { },
                modifier = Modifier.weight(1f),
            )

            Button(
                onClick = {
                },
                modifier = Modifier.align(Alignment.CenterVertically),
            ) {
                Text("Test")
            }
        }

        TestPlatformView(Modifier.weight(1f))
    }
}
expect fun TestPlatformView(modifier: Modifier)

// Android
@Composable
actual fun TestPlatformView(modifier: Modifier) {
    AndroidView(
        factory = { context ->
            TextView(context).apply {
                this.text = Array(100) { "$it" }.joinToString("\n")
            }
        },
    )
}

// iOS
@Composable
actual fun TestPlatformView(modifier: Modifier) {
    UIKitView(
        factory = {
            UITextView().apply {
                this.text = Array(100) { "$it" }.joinToString("\n")
            }
        },
        modifier = modifier,
    )
}

Expected behavior UITextView shouldn't be overlapped.

Additional context If wrap UIKitView with Box, the issue will be gone:

Box(modifier) {
   UIKitView(modifier = Modifier.fillMaxSize(), ...)
}
elijah-semyonov commented 11 months ago

If you replace TestPlatformView(Modifier.weight(1f)) with TestPlatformView(Modifier.fillMaxSize()) it's also working well.

elijah-semyonov commented 9 months ago

UIKitView widget doesn't properly communicate its layout when used alone.