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.24k stars 1.11k forks source link

ComposeUiViewController with nested scrollable column shrinks Column with UIModalPresentationFormSheet #4850

Open nilufer32 opened 1 month ago

nilufer32 commented 1 month ago

Describe the bug A clear and concise description of what the bug is. When using ComposeUiViewController, and setting the modalPresentationStyle of the view controller to UIModalPresentationFormSheet, dragging the form sheet updwards/downwards causes shrinking/stretching of the nested composable scrollable column I place inside it. Also im not able to vertically scroll my column.

Affected platforms

IOS

Versions

To reproduce:

val bottomSheetUIViewController =
        ComposeUIViewController {
            VerticalScrollWithIndependentHorizontalRows()
        }
        bottomSheetUIViewController.modalPresentationStyle = UIModalPresentationFormSheet
        bottomSheetUIViewController.sheetPresentationController?.setDetents(
        listOf(
                    UISheetPresentationControllerDetent.mediumDetent(),
                    UISheetPresentationControllerDetent.largeDetent(),
                )
                )

                UIApplication.sharedApplication.keyWindow?.rootViewController?.presentViewController(
            viewControllerToPresent = bottomSheetUIViewController,
            animated = true,
            completion = {},
        )

 @Composable
fun VerticalScrollWithIndependentHorizontalRows() {
    Column(
        modifier =
            Modifier.fillMaxSize().verticalScroll(verticalScrollState, enabled = true),
    ) {
        repeat(10) { rowIndex ->
            val horizontalScrollState = rememberScrollState()

            Spacer(Modifier.height(30.dp).background(Color.DarkGray))
            Row(
                modifier =
                    Modifier
                        .padding(start = 16.dp, end = 16.dp)
                        .horizontalScroll(horizontalScrollState),
            ) {
                repeat(5) {
                    Box(
                        modifier =
                            Modifier
                                .size(100.dp)
                                .background(Color.Gray),
                    ) {
                        Text("Item $it in row $rowIndex")
                    }
                }
            }
        }
    }
}

Video depicting the bug :

https://github.com/JetBrains/compose-multiplatform/assets/151455263/924b9ce3-0c92-4aca-b55b-5338c5e90431

Additional Warning: When attempting to scroll in my nested vertically scrollable column, I receive the following logs in Xcode: DidReceiveMemoryWarning

nilufer32 commented 1 month ago

any updates on this issue?

elijah-semyonov commented 4 weeks ago

I'll have a look at it soon.

elijah-semyonov commented 4 weeks ago

The nested scrolling issue is a separate one: https://github.com/JetBrains/compose-multiplatform/issues/3806

nilufer32 commented 4 weeks ago

But is the scrolling issue related to the shrinking/stretching of the content?

elijah-semyonov commented 3 weeks ago

Not really

elijah-semyonov commented 3 weeks ago

Memory warning doesn't seem to be related to the repro you posted. Most likely you have a retain cycle between Kotlin and ObjC with a strong reference inside ObjC API that Kotlin can't break.

nilufer32 commented 3 weeks ago

@elijah-semyonov I dont really see how could that be the case as the prototype app I used to reproduce the bug uses the standard architecture of a multiplatform app where I simply use a ComposeUIViewController from swift, and to this view controller I add the sample code above

elijah-semyonov commented 3 weeks ago

Do you mind sharing the whole solution? "DidReceiveMemoryWarning" means something went terribly wrong.

nilufer32 commented 3 weeks ago

all I do to trigger the memory warning is attempt to scroll inside the column in my bottom sheet by scrolling multiple times consecutively. this actually does scroll inside my column but at an extremely slow pace as in every scroll event scrolls the column by 1 pixel roughly

elijah-semyonov commented 3 weeks ago

Can you record it? I fail to reproduce this behavior.

nilufer32 commented 3 weeks ago

sure ill record it right now

nilufer32 commented 3 weeks ago

Here's the repo containing the reproduction code: https://github.com/nilufer32/test

https://github.com/JetBrains/compose-multiplatform/assets/151455263/472c9299-9d61-4987-af14-dcde8d95db49

Screenshot 2024-06-05 at 12 27 03 PM
elijah-semyonov commented 2 weeks ago

@nilufer32 You've got wrong Compose Version in repro 🌚 compose = "1.5.11"

elijah-semyonov commented 2 weeks ago

Reproduced memory spike though

nilufer32 commented 2 weeks ago

the issue is 100% reproducible using compose 1.6.10 and kotlin 2.0.0. I just seem to have forgotten to update the library versions when I was creating a sample app to post for you onto github :)

elijah-semyonov commented 2 weeks ago

A memory spike part of the issue should be fixed in https://github.com/JetBrains/compose-multiplatform-core/pull/1390