Hi, i am currently trying out compose 1.10.0-beta0...
# compose-ios
f
Hi, i am currently trying out compose 1.10.0-beta01 and stumbled on this changelog. I am trying to use autoresize uikit without assigning the default value. But it does not work. Here is the code snippet :
Copy code
UIKitView(
    factory = {
        val webView =
            wkwebviewInstance(
                url = url(),
                token = token,
                onSizeChange = {
                },
                backgroundColor = backgroundColor,
            )
        webView.navigationDelegate = coord
        webView.UIDelegate = coord
        webView
    },
    modifier =
        Modifier
            .fillMaxWidth()
            .wrapContentHeight()
            .background(Color.Transparent),
    update = { webView ->
        webView.backgroundColor = backgroundColor.toUiColor()
        webView.loadHTMLString(url(), null)
    },
    properties = UIKitInteropProperties(placedAsOverlay = true),
)
a
Unlike several UI components, like UILabel, UIButton of SwiftUI view, WKWebView as a component does not have self-sizing capabilities - you have to specify its size when using it.
✅ 1
f
Ahh i see, thank you
Hi ! I have this Rich Text Element : struct RichTextUI : View { let htmlData :()->String let backgroundColor :()->Color let textColor :()->Color *init*(htmlData: @escaping () -> String, backgroundColor: @escaping () -> Color, textColor: @escaping () -> Color) { self.htmlData = htmlData self.backgroundColor = backgroundColor self.textColor = textColor } var body : some View { RichText(html : self.htmlData()) .placeholder(content: { ProgressView() }) .backgroundColor(.color(backgroundColor())) .fontType(.system) .textColor(light: textColor(), dark: textColor()) .fixedSize(horizontal: false, vertical: true) } } and called it in compose as such : func swiftUiRichText(data: String, backgroundColor: @escaping () -> UIColor, textColor: @escaping () -> UIColor) -> UIView { let richView = RichTextUI(htmlData: {data},backgroundColor: { Color(uiColor: backgroundColor()) },textColor: { Color(uiColor: textColor()) }) let controller = UIHostingController(rootView: richView) controller.view.translatesAutoresizingMaskIntoConstraints = false return controller.view } without defining fixed size. Why cant the view be self sizing ? or is there missing steps ?
a
2 things that I see here: • You need to embed entire UIHostingController, but not its view. Use
UIKitViewController
for this • no need to change
translatesAutoresizingMaskIntoConstraints
From the other side, I don't know how the
RichText
view is implemented - I suppose it's a 3rd party library. If changing the first 2 things won't help, please file an issue in our YouTrack and attach the full reproducer that shows the issue.
✅ 1