NuPlay / RichText

Easily show RichText(html) in SwiftUI
MIT License
209 stars 36 forks source link

Handling combine/state changes? #10

Closed wrunk closed 2 years ago

wrunk commented 2 years ago

Hello and thank you for sharing this! It appears to be working really well for the initial render, but from your example in the readme, changes to the @State var html won't be reflected by the webview. It seems like this function updateUIView would need to get implemented yea? I took a quick pass at this, so lmk if this seems reasonable and ill make a PR:

public func updateUIView(_ uiView: WKWebView, context: Context) {
        let htmlStart = """
            <HTML>
            <head>
                <meta name='viewport' content='width=device-width, shrink-to-fit=YES, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no'>
            </head>
            """
        let htmlEnd = "</BODY></HTML>"
        let htmlString = "\(htmlStart)\(css(colorScheme: self.colorScheme))\(html)\(htmlEnd)"
        uiView.loadHTMLString(htmlString, baseURL:  nil)
    }

I guess we might want to factor that bit out of makeUIView and updateUIView

NuPlay commented 2 years ago

I'm really sorry I misunderstood what you said, so I made a commit, Really sorry for blocking your contribution

NuPlay commented 2 years ago

I canceled that commit, please make a PR

wrunk commented 2 years ago

100% no worries man, please revert the revert :) I will follow the project and help out should there be another need! TBH I'm still learning swift/swiftUI so happy to help in the future