Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ios): addSubview instead of setContentView #655

Merged
merged 1 commit into from
Aug 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/ios-subview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": patch
---

On iOS, add webview as subview instead of replacing original view.
22 changes: 15 additions & 7 deletions src/webview/wkwebview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,24 @@ impl InnerWebView {
// [preference setValue:@YES forKey:@"fullScreenEnabled"];
let _: id = msg_send![_preference, setValue:_yes forKey:NSString::new("fullScreenEnabled")];

// Initialize webview with zero point
let zero = CGRect::new(&CGPoint::new(0., 0.), &CGSize::new(0., 0.));
let _: () = msg_send![webview, initWithFrame:zero configuration:config];

// Auto-resize on macOS
#[cfg(target_os = "macos")]
{
// Initialize webview with zero point
let zero = CGRect::new(&CGPoint::new(0., 0.), &CGSize::new(0., 0.));
let _: () = msg_send![webview, initWithFrame:zero configuration:config];
// Auto-resize on macOS
webview.setAutoresizingMask_(NSViewHeightSizable | NSViewWidthSizable);
}

#[cfg(target_os = "ios")]
{
let ui_view = window.ui_view() as id;
let frame: CGRect = msg_send![ui_view, frame];
// set all autoresizingmasks
let () = msg_send![webview, setAutoresizingMask: 31];
let _: () = msg_send![webview, initWithFrame:frame configuration:config];
}

// Message handler
let ipc_handler_ptr = if let Some(ipc_handler) = attributes.ipc_handler {
let cls = ClassDecl::new("WebViewDelegate", class!(NSObject));
Expand Down Expand Up @@ -520,8 +528,8 @@ r#"Object.defineProperty(window, 'ipc', {

#[cfg(target_os = "ios")]
{
let ui_window = window.ui_window() as id;
let _: () = msg_send![ui_window, setContentView: webview];
let ui_view = window.ui_view() as id;
let _: () = msg_send![ui_view, addSubview: webview];
}

Ok(w)
Expand Down