feat(webview): Allow loading of HTML string instead of URL.

This commit is contained in:
David Lemarier 2021-04-26 08:09:13 -04:00
parent be6ff21d11
commit 5ec3b172e8
No known key found for this signature in database
GPG key ID: 414D7F0DBBB895CA

View file

@ -253,6 +253,15 @@ impl<T> WebView<T> {
});
}
/// Given a HTML string, instructs the WebView to load it.
/// Usefull for small html file, but better to use custom protocol.
pub fn load_html(&self, html_string: &str) {
self.objc.with_mut(|obj| unsafe {
let empty: id = msg_send![class!(NSURL), URLWithString: NSString::new("")];
let _: () = msg_send![&*obj, loadHTMLString:NSString::new(html_string) baseURL:empty];
});
}
/// Go back in history, if possible.
pub fn go_back(&self) {
self.objc.with_mut(|obj| unsafe {