mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-21 17:41:25 -08:00
fix(ios): hide the WKWebView input accessory bar
This commit is contained in:
4 files changed
+57
No files matched your search
Generated
+1
@@ -3981,6 +3981,7 @@ dependencies = [
|
||||
"gtk",
|
||||
"jni",
|
||||
"log",
|
||||
"objc2",
|
||||
"percent-encoding",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
||||
@@ -70,6 +70,9 @@ tauri-plugin-notifications = { git = "https://github.com/Choochmeque/tauri-plugi
|
||||
] }
|
||||
tauri-plugin-edge-to-edge = { git = "https://github.com/SableClient/tauri-plugin-edge-to-edge.git", rev = "33c6116c27be28c06df5a9d02231ecc5fdeb93c5" }
|
||||
|
||||
[target.'cfg(target_os = "ios")'.dependencies]
|
||||
objc2 = "0.6"
|
||||
|
||||
[target.'cfg(target_os = "android")'.dependencies]
|
||||
tauri-plugin-android-fs = "=28.4.0"
|
||||
tauri-plugin-unifiedpush = { path = "plugins/tauri-plugin-unifiedpush" }
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
// iOS shows a form accessory bar (prev/next arrows + Done) above the keyboard
|
||||
// for web inputs. WKWebView exposes no API to disable it, so swap the private
|
||||
// WKContentView's class for a runtime subclass whose inputAccessoryView is nil,
|
||||
// the same approach as Capacitor's hideFormAccessoryBar.
|
||||
|
||||
use std::ffi::CString;
|
||||
|
||||
use objc2::runtime::{AnyClass, AnyObject, ClassBuilder, Sel};
|
||||
use objc2::{msg_send, sel};
|
||||
use tauri::webview::WebviewWindow;
|
||||
|
||||
extern "C-unwind" fn input_accessory_view_nil(_this: &AnyObject, _cmd: Sel) -> *mut AnyObject {
|
||||
std::ptr::null_mut()
|
||||
}
|
||||
|
||||
pub fn hide_form_accessory_bar(window: &WebviewWindow<crate::BrowserEngine>) {
|
||||
let _ = window.with_webview(|webview| unsafe {
|
||||
let webview: *mut AnyObject = webview.inner().cast();
|
||||
let scroll_view: *mut AnyObject = msg_send![&*webview, scrollView];
|
||||
let subviews: *mut AnyObject = msg_send![&*scroll_view, subviews];
|
||||
let count: usize = msg_send![&*subviews, count];
|
||||
for index in 0..count {
|
||||
let subview: *mut AnyObject = msg_send![&*subviews, objectAtIndex: index];
|
||||
let class = (*subview).class();
|
||||
if !class.name().to_bytes().starts_with(b"WKContent") {
|
||||
continue;
|
||||
}
|
||||
let Ok(subclass_name) = CString::new(format!(
|
||||
"{}_NoAccessoryBar",
|
||||
class.name().to_string_lossy()
|
||||
)) else {
|
||||
continue;
|
||||
};
|
||||
let subclass = AnyClass::get(&subclass_name).unwrap_or_else(|| {
|
||||
let mut builder = ClassBuilder::new(&subclass_name, class)
|
||||
.expect("accessory bar subclass already registered");
|
||||
builder.add_method(
|
||||
sel!(inputAccessoryView),
|
||||
input_accessory_view_nil as extern "C-unwind" fn(_, _) -> _,
|
||||
);
|
||||
builder.register()
|
||||
});
|
||||
AnyObject::set_class(&*subview, subclass);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
#[cfg(desktop)]
|
||||
mod desktop;
|
||||
#[cfg(target_os = "ios")]
|
||||
mod ios;
|
||||
#[cfg(target_os = "android")]
|
||||
mod mobile;
|
||||
mod network;
|
||||
@@ -234,6 +236,11 @@ pub fn run() {
|
||||
|
||||
show_or_create_main_window(app.handle())?;
|
||||
|
||||
#[cfg(target_os = "ios")]
|
||||
if let Some(window) = app.get_webview_window(MAIN_WINDOW_LABEL) {
|
||||
ios::hide_form_accessory_bar(&window);
|
||||
}
|
||||
|
||||
#[cfg(desktop)]
|
||||
desktop::tray::sync_desktop_settings_inner(app.handle())?;
|
||||
|
||||
|
||||
Reference in new issue
Block a user