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.84k stars 1.15k forks source link

Compose inside `UIViewControllerRepresentable` doesn't properly communicate its layout with SwiftUI. #4169

Open joyzem opened 7 months ago

joyzem commented 7 months ago

Describe the bug When you use Compose Multiplatform though UIViewControllerRepresentable SwiftUI interop API, a composable function is not rendering if it is called inside the ScrollView

Affected platforms Select one of the platforms below:

Versions

To Reproduce Steps and/or the code snippet to reproduce the behavior:

  1. Create any composable function with content inside it
  2. Create SwiftUI interop container through UIViewControllerRepresentable
  3. Call this in SwiftUI ScrollView container
  4. See the composable function is not rendering

Expected behavior Composable function should be rendered

Additional context The composable function is rendering without any problems when it is used inside VStack

elijah-semyonov commented 7 months ago

Hi, thanks for report. We currently didn't dig deep into SwiftUI layout mechanism so there is a chance that Representable widget can't properly calculate its intrinsic size. Does the problem persist when you explicitly use .frame modifier on it?

joyzem commented 7 months ago

Thanks for the answer! I forgot to mention about .frame modifier.. This helps, but suddenly the size of my composable is not static and it is useless in my case. By the way, Compose Multiplatform is great! I'm waiting for new releases and I have fully Compose Multiplatform app in App Store :)

elijah-semyonov commented 7 months ago

That's nice to hear! I understand your use case. It sounds completely legit and we'll be looking into what we can do about it.

harry248 commented 1 month ago

Any updates on this? We currently have to use the workaround suggested by John O'Reilly but that requires a lot of boilerplate code.

elijah-semyonov commented 1 month ago

Still not, did you try experimenting with setting up a width NSLayoutConstraint manually on view of interop view controller and trying to figure out its height to pass to Compose using https://developer.apple.com/documentation/uikit/uiview/1622624-systemlayoutsizefittingsize?

harry248 commented 1 month ago

Unfortunately, I don't quite understand the answer. Can you perhaps give me an example? If I understand it correctly, should I calculate the size in the Swift part and pass it through to the composable? But how is that supposed to work, because I need the intrinsic size of the composable and if I don't pass it through from the composable to the Swift part, it just seems to be 0.

okushnikov commented 1 week ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

okushnikov commented 1 week ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.