From 409d887cacc70cd6f7876462327f2ae79d9756a4 Mon Sep 17 00:00:00 2001 From: Anthony Ronning <101225832+AnthonyRonning@users.noreply.github.com> Date: Mon, 2 Nov 2026 01:12:59 +0000 Subject: [PATCH] Paint iOS safe-area strips with the page background again wry 0.57 (tauri-apps/wry#1824, pulled in by the Tauri 2.12 upgrade) makes the iOS WKWebView non-opaque with a systemBackgroundColor background. The page uses viewport-fit=auto, so the strips by the status bar and home indicator turned plain black (dark) or white (light) instead of the page background. Make the WebView opaque after the first page load so WebKit paints them from the page again, without the white launch flash that an opaque WebView shows before the first paint. Co-Authored-By: Claude Opus 5.5 --- .../frontend/src-tauri/Cargo.lock | 1 + .../frontend/src-tauri/Cargo.toml | 1 + .../src-tauri/src/ios_webview_background.rs | 33 +++++++++++++++++++ .../frontend/src-tauri/src/lib.rs | 3 ++ 4 files changed, 38 insertions(+) create mode 100644 apps/maple-research/frontend/src-tauri/src/ios_webview_background.rs diff --git a/apps/maple-research/frontend/src-tauri/Cargo.lock b/apps/maple-research/frontend/src-tauri/Cargo.lock index b4e25b3b9..cee5ab784 100644 --- a/apps/maple-research/frontend/src-tauri/Cargo.lock +++ b/apps/maple-research/frontend/src-tauri/Cargo.lock @@ -3607,6 +3607,7 @@ dependencies = [ "log", "maple-proxy", "maple-sdk", + "objc2 0.6.4", "objc2-app-kit", "objc2-foundation 0.3.2", "office_oxide", diff --git a/apps/maple-research/frontend/src-tauri/Cargo.toml b/apps/maple-research/frontend/src-tauri/Cargo.toml index b02036d92..fc3fc90bf 100644 --- a/apps/maple-research/frontend/src-tauri/Cargo.toml +++ b/apps/maple-research/frontend/src-tauri/Cargo.toml @@ -77,6 +77,7 @@ objc2-app-kit = { version = "0.3.2", default-features = false, features = ["std" objc2-foundation = { version = "0.3.2", default-features = false, features = ["std", "NSString"] } [target.'cfg(target_os = "ios")'.dependencies] +objc2 = "0.6" tauri-plugin-iap = { path = "plugins/tauri-plugin-iap" } # We build ONNX Runtime 1.23.2 from source for iOS (see scripts/build-ios-onnxruntime.sh) # We disable download-binaries and copy-dylibs since we link our own xcframework diff --git a/apps/maple-research/frontend/src-tauri/src/ios_webview_background.rs b/apps/maple-research/frontend/src-tauri/src/ios_webview_background.rs new file mode 100644 index 000000000..58348dc5a --- /dev/null +++ b/apps/maple-research/frontend/src-tauri/src/ios_webview_background.rs @@ -0,0 +1,33 @@ +use objc2::{msg_send, runtime::AnyObject}; +use tauri::{webview::PageLoadEvent, webview::PageLoadPayload, Runtime, Webview}; + +/// Lets WebKit paint the safe-area strips with the page background again. +/// +/// wry 0.57 (tauri-apps/wry#1824) makes the iOS WKWebView non-opaque with a +/// `systemBackgroundColor` background. The page uses `viewport-fit=auto`, so +/// the strips beside the status bar and home indicator then show plain white +/// or black instead of the page background. An opaque WebView paints them +/// from the page, as it did before the Tauri 2.12 upgrade. +/// +/// This waits for the first page load: an opaque WebView flashes white before +/// the page paints, which is what wry's change avoids at launch. +pub fn on_page_load(webview: &Webview, payload: &PageLoadPayload<'_>) { + if payload.event() != PageLoadEvent::Finished { + return; + } + + let result = webview.with_webview(|webview| { + let wk_webview = webview.inner().cast::(); + if wk_webview.is_null() { + return; + } + // SAFETY: on iOS `inner()` is the live WKWebView, and `with_webview` + // runs this closure on the main thread. + unsafe { + let _: () = msg_send![&*wk_webview, setOpaque: true]; + } + }); + if let Err(error) = result { + log::warn!("Failed to make webview {} opaque: {error}", webview.label()); + } +} diff --git a/apps/maple-research/frontend/src-tauri/src/lib.rs b/apps/maple-research/frontend/src-tauri/src/lib.rs index cca16932a..ad7c16fa6 100644 --- a/apps/maple-research/frontend/src-tauri/src/lib.rs +++ b/apps/maple-research/frontend/src-tauri/src/lib.rs @@ -4,6 +4,8 @@ use tauri_plugin_deep_link::DeepLinkExt; mod desktop_app_profile; #[cfg(test)] mod ios_app_variant; +#[cfg(target_os = "ios")] +mod ios_webview_background; #[cfg(any(desktop, target_os = "ios"))] mod legacy_tts_cleanup; mod native_oauth; @@ -515,6 +517,7 @@ pub fn run() { // iOS-specific configuration #[cfg(all(not(desktop), target_os = "ios"))] let app = builder + .on_page_load(ios_webview_background::on_page_load) .invoke_handler(tauri::generate_handler![ storekit_experiment::storekit_experiment_enabled, pdf_extractor::extract_document_content,