Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(mobile/ios): remove accessory bar from keyboard
AndreeaCorlaci1a318e1615eb
diff --git a/apps/mobile/android/app/capacitor.build.gradle b/apps/mobile/android/app/capacitor.build.gradleindex bbfb44fad1..b115bcf460 100644--- a/apps/mobile/android/app/capacitor.build.gradle+++ b/apps/mobile/android/app/capacitor.build.gradle@@ -9,7 +9,7 @@ android {apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"dependencies {-+ implementation project(':capacitor-keyboard')}diff --git a/apps/mobile/android/capacitor.settings.gradle b/apps/mobile/android/capacitor.settings.gradleindex a8bab3574d..8c9df8ec2a 100644--- a/apps/mobile/android/capacitor.settings.gradle+++ b/apps/mobile/android/capacitor.settings.gradle@@ -1,3 +1,6 @@// DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUNinclude ':capacitor-android'project(':capacitor-android').projectDir = new File('../../../node_modules/@capacitor/android/capacitor')++include ':capacitor-keyboard'+project(':capacitor-keyboard').projectDir = new File('../../../node_modules/@capacitor/keyboard/android')diff --git a/apps/mobile/capacitor.config.json b/apps/mobile/capacitor.config.jsonindex 5a2ac43394..440853143d 100644--- a/apps/mobile/capacitor.config.json+++ b/apps/mobile/capacitor.config.json@@ -10,5 +10,9 @@"ios": {"limitsNavigationsToAppBoundDomains": true},- "plugins": {}+ "plugins": {+ "Keyboard": {+ "resize": "native"+ }+ }}diff --git a/apps/mobile/ios/App/App/ViewController.swift b/apps/mobile/ios/App/App/ViewController.swiftindex 5cd7696bc5..f9c3bf14a2 100644--- a/apps/mobile/ios/App/App/ViewController.swift+++ b/apps/mobile/ios/App/App/ViewController.swift@@ -1,4 +1,62 @@import UIKitimport Capacitor+import WebKit+import ObjectiveC.runtime-class ViewController: CAPBridgeViewController {}+class ViewController: CAPBridgeViewController {+ override func viewDidLoad() {+ super.viewDidLoad()+ hideKeyboardInputAccessoryView()+ enableInteractiveKeyboardDismiss()+ }++ // Because we hide iOS's input accessory bar (which contains the Done+ // button), the user would otherwise have no native way to dismiss the+ // keyboard. Enable interactive swipe-down dismissal on the web view's+ // scroll view — this is the same gesture Messages, Mail, and most+ // first-party iOS apps use. Dragging the content area downward follows+ // the finger and hides the keyboard when it reaches the bottom.+ private func enableInteractiveKeyboardDismiss() {+ guard let webView = self.webView else { return }+ webView.scrollView.keyboardDismissMode = .interactive+ }++ // The iOS keyboard shows a native "input accessory view" above the+ // software keyboard — the row with Prev/Next arrows and the Done button.+ // Capacitor's `Keyboard.resize: native` resizes the web view above the+ // keyboard itself, but the accessory view sits on top of that and+ // overlaps the editor toolbar. We hide it by dynamically subclassing+ // WebKit's internal WKContentView and overriding `inputAccessoryView`+ // to return nil. This is the canonical way to remove it in WKWebView+ // apps and doesn't depend on the @capacitor/keyboard JS bridge being+ // reachable at call time.+ private func hideKeyboardInputAccessoryView() {+ guard let webView = self.webView else { return }+ guard let contentView = webView.scrollView.subviews.first(where: {+ String(describing: type(of: $0)).contains("WKContent")+ }) else { return }++ let originalClass: AnyClass = type(of: contentView)+ let subclassName = "TriliumNoAccessoryView_\(NSStringFromClass(originalClass))"++ // If we've already generated the subclass on a previous run, reuse it.+ if let existing = NSClassFromString(subclassName) {+ object_setClass(contentView, existing)+ return+ }++ guard let subclass = objc_allocateClassPair(originalClass, subclassName, 0) else {+ return+ }++ let selector = NSSelectorFromString("inputAccessoryView")+ if let method = class_getInstanceMethod(UIView.self, selector) {+ let block: @convention(block) (AnyObject) -> UIView? = { _ in nil }+ let implementation = imp_implementationWithBlock(block)+ class_addMethod(subclass, selector, implementation, method_getTypeEncoding(method))+ }++ objc_registerClassPair(subclass)+ object_setClass(contentView, subclass)+ }+}diff --git a/apps/mobile/ios/App/CapApp-SPM/Package.swift b/apps/mobile/ios/App/CapApp-SPM/Package.swiftindex 8c90a72b1f..fe8dfa9349 100644--- a/apps/mobile/ios/App/CapApp-SPM/Package.swift+++ b/apps/mobile/ios/App/CapApp-SPM/Package.swift@@ -11,14 +11,16 @@ let package = Package(targets: ["CapApp-SPM"])],dependencies: [- .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", exact: "8.3.1")+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", exact: "8.3.1"),+ .package(name: "CapacitorKeyboard", path: "../../../../../node_modules/@capacitor/keyboard")],targets: [.target(name: "CapApp-SPM",dependencies: [.product(name: "Capacitor", package: "capacitor-swift-pm"),- .product(name: "Cordova", package: "capacitor-swift-pm")+ .product(name: "Cordova", package: "capacitor-swift-pm"),+ .product(name: "CapacitorKeyboard", package: "CapacitorKeyboard")])]diff --git a/apps/mobile/package.json b/apps/mobile/package.jsonindex 29ad988494..d2b0836a54 100644--- a/apps/mobile/package.json+++ b/apps/mobile/package.json@@ -14,7 +14,8 @@"dependencies": {"@capacitor/android": "8.3.1","@capacitor/core": "8.3.1",- "@capacitor/ios": "8.3.1"+ "@capacitor/ios": "8.3.1",+ "@capacitor/keyboard": "8.0.1"},"devDependencies": {"@capacitor/cli": "8.3.1"diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex aae41f7427..a1f9eeb6a3 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -819,6 +819,9 @@ importers:'@capacitor/ios':specifier: 8.3.1version: 8.3.1(@capacitor/[email protected])+ '@capacitor/keyboard':+ specifier: 8.0.1+ version: 8.0.1(@capacitor/[email protected])devDependencies:'@capacitor/cli':specifier: 8.3.1@@ -2007,6 +2010,11 @@ packages:peerDependencies:'@capacitor/core': ^8.3.0+ '@capacitor/[email protected]':+ resolution: {integrity: sha512-HDf4qrvvhLRMsgBoqeqIld6hP8JMK/WPbCYMvz8ajhY6TaibYt6B+NQyky4oIPCOfHTz5OcVsuHkbb8fQvGDAg==}+ peerDependencies:+ '@capacitor/core': '>=8.0.0'+'@catppuccin/[email protected]':resolution: {integrity: sha512-P1ZCj4DZVLqr/TNz28m3aaF2Elrikpb8OOnzN0Vyf95Un4pTWTkCSvhbskbnJbnNJ87Rfvt3fXoaUj4o55X30Q==}@@ -15025,6 +15033,10 @@ snapshots:dependencies:'@capacitor/core': 8.3.1+ '@capacitor/[email protected](@capacitor/[email protected])':+ dependencies:+ '@capacitor/core': 8.3.1+'@catppuccin/[email protected]':dependencies:'@catppuccin/palette': 1.7.1