John O'Reilly
04/30/2023, 4:12 PMandrew
04/30/2023, 5:01 PMandrew
04/30/2023, 5:02 PMDima Avdeev
05/01/2023, 5:07 PMJohn O'Reilly
05/01/2023, 5:23 PMDima Avdeev
05/01/2023, 5:25 PMJohn O'Reilly
05/01/2023, 5:28 PMJohn O'Reilly
05/01/2023, 8:26 PMonGloballyPositioned
) that seems to work (emphasis on "hack"!). First hacky part is that I need to use a frame
initially with height larger than it should need.
In my Kotlin code then I have
fun SessionSpeakerInfoViewController(speaker: SpeakerDetails, onSocialLinkClicked: (String) -> Unit, heightChanged: (Int) -> Unit): UIViewController =
ComposeUIViewController {
MaterialTheme {
Column(
modifier = Modifier
.onGloballyPositioned { coordinates ->
heightChanged(coordinates.size.height)
}
) {
SessionSpeakerInfo(speaker, onSocialLinkClicked)
}
}
}
In SwiftUI I have
struct SessionSpeakerInfoViewShared: UIViewControllerRepresentable {
var speaker: SpeakerDetails
@Binding var measuredHeight: CGFloat
@Environment(\.openURL) var openURL
func makeUIViewController(context: Context) -> UIViewController {
let content = SharedViewControllersKt.SessionSpeakerInfoViewController(speaker: speaker, onSocialLinkClicked: { urlString in
if let url = URL(string: urlString) {
openURL(url)
}
}, heightChanged: { height in
measuredHeight = CGFloat(height)
})
return content
}
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
}
}
and then
@State var measuredHeight: CGFloat = 1000
...
VStack {
SessionSpeakerInfoViewShared(speaker: speaker.speakerDetails, measuredHeight: $measuredHeight)
}
.frame(height: measuredHeight)
(also still need to convert the units)John O'Reilly
05/01/2023, 8:39 PMandrew
05/01/2023, 8:46 PMJohn O'Reilly
05/01/2023, 8:54 PMandrew
05/01/2023, 8:55 PMandrew
05/01/2023, 8:57 PMDmitriy Tarasevich
01/19/2024, 2:35 AMJohn O'Reilly
01/19/2024, 7:37 AMDmitriy Tarasevich
01/19/2024, 1:49 PM.wrapContentHeight(unbounded = true)
on the composable being wrapped with a
ComposeUIViewController
harry248
07/16/2024, 6:24 AM.wrapContentHeight(unbound=true)
seems to allow the initial frame height to be set to 1
instead of a large value.