Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

feat(android): implement capacitor/keyboard plugin (#10125)

aki-chang-dev67301221083a
diff --git a/packages/frontend/apps/android/App/app/capacitor.build.gradle b/packages/frontend/apps/android/App/app/capacitor.build.gradle
index aebef209b3..464e4cd448 100644
--- a/packages/frontend/apps/android/App/app/capacitor.build.gradle
+++ b/packages/frontend/apps/android/App/app/capacitor.build.gradle
@@ -10,6 +10,7 @@ android {
apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
dependencies {
implementation project(':capacitor-app')
+ implementation project(':capacitor-keyboard')
implementation project(':capgo-inappbrowser')
}
diff --git a/packages/frontend/apps/android/App/app/src/main/java/app/affine/pro/MainActivity.kt b/packages/frontend/apps/android/App/app/src/main/java/app/affine/pro/MainActivity.kt
index 8d50a9f2f6..bbba5edb91 100644
--- a/packages/frontend/apps/android/App/app/src/main/java/app/affine/pro/MainActivity.kt
+++ b/packages/frontend/apps/android/App/app/src/main/java/app/affine/pro/MainActivity.kt
@@ -3,6 +3,7 @@ package app.affine.pro
import android.os.Build
import android.os.Bundle
import androidx.annotation.RequiresApi
+import com.capacitorjs.plugins.keyboard.KeyboardPlugin
import com.getcapacitor.BridgeActivity
import com.getcapacitor.plugin.CapacitorCookies
import com.getcapacitor.plugin.CapacitorHttp
@@ -17,7 +18,8 @@ class MainActivity : BridgeActivity() {
listOf(
CapacitorHttp::class.java,
CapacitorCookies::class.java,
- InAppBrowserPlugin::class.java
+ InAppBrowserPlugin::class.java,
+ KeyboardPlugin::class.java,
)
)
}
diff --git a/packages/frontend/apps/android/App/capacitor.settings.gradle b/packages/frontend/apps/android/App/capacitor.settings.gradle
index ac95c8a879..46eaad7d0b 100644
--- a/packages/frontend/apps/android/App/capacitor.settings.gradle
+++ b/packages/frontend/apps/android/App/capacitor.settings.gradle
@@ -5,5 +5,8 @@ project(':capacitor-android').projectDir = new File('../../../../../node_modules
include ':capacitor-app'
project(':capacitor-app').projectDir = new File('../../../../../node_modules/@capacitor/app/android')
+include ':capacitor-keyboard'
+project(':capacitor-keyboard').projectDir = new File('../../../../../node_modules/@capacitor/keyboard/android')
+
include ':capgo-inappbrowser'
project(':capgo-inappbrowser').projectDir = new File('../../../../../node_modules/@capgo/inappbrowser/android')
diff --git a/packages/frontend/apps/android/package.json b/packages/frontend/apps/android/package.json
index 2deec0992f..31886c97ed 100644
--- a/packages/frontend/apps/android/package.json
+++ b/packages/frontend/apps/android/package.json
@@ -17,7 +17,8 @@
"@capacitor/android": "^7.0.0",
"@capacitor/app": "^7.0.0",
"@capacitor/core": "^7.0.0",
- "@capgo/inappbrowser": "^7.0.0",
+ "@capacitor/keyboard": "^7.0.0",
+ "@capgo/inappbrowser": "^7.1.0",
"@sentry/react": "^8.44.0",
"@toeverything/infra": "workspace:*",
"react": "^19.0.0",
diff --git a/packages/frontend/apps/android/src/app.tsx b/packages/frontend/apps/android/src/app.tsx
index 26bd12581b..0407839efd 100644
--- a/packages/frontend/apps/android/src/app.tsx
+++ b/packages/frontend/apps/android/src/app.tsx
@@ -1,6 +1,7 @@
import { AffineContext } from '@affine/core/components/context';
import { AppFallback } from '@affine/core/mobile/components/app-fallback';
import { configureMobileModules } from '@affine/core/mobile/modules';
+import { VirtualKeyboardProvider } from '@affine/core/mobile/modules/virtual-keyboard';
import { router } from '@affine/core/mobile/router';
import { configureCommonModules } from '@affine/core/modules';
import { AuthService, DefaultServerService } from '@affine/core/modules/cloud';
@@ -16,6 +17,7 @@ import { configureBrowserWorkbenchModule } from '@affine/core/modules/workbench'
import { configureBrowserWorkspaceFlavours } from '@affine/core/modules/workspace-engine';
import { StoreManagerClient } from '@affine/nbstore/worker/client';
import { App as CapacitorApp } from '@capacitor/app';
+import { Keyboard } from '@capacitor/keyboard';
import { InAppBrowser } from '@capgo/inappbrowser';
import { Framework, FrameworkRoot, getCurrentStore } from '@toeverything/infra';
import { OpClient } from '@toeverything/infra/op';
@@ -70,6 +72,19 @@ framework.impl(ClientSchemeProvider, {
},
});
+framework.impl(VirtualKeyboardProvider, {
+ addEventListener: (event, callback) => {
+ Keyboard.addListener(event as any, callback as any).catch(e => {
+ console.error(e);
+ });
+ },
+ removeAllListeners: () => {
+ Keyboard.removeAllListeners().catch(e => {
+ console.error(e);
+ });
+ },
+});
+
// setup application lifecycle events, and emit application start event
window.addEventListener('focus', () => {
frameworkProvider.get(LifecycleService).applicationFocus();
diff --git a/yarn.lock b/yarn.lock
index 526d67de6d..d5ec44d7c8 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -230,7 +230,8 @@ __metadata:
"@capacitor/app": "npm:^7.0.0"
"@capacitor/cli": "npm:^7.0.0"
"@capacitor/core": "npm:^7.0.0"
- "@capgo/inappbrowser": "npm:^7.0.0"
+ "@capacitor/keyboard": "npm:^7.0.0"
+ "@capgo/inappbrowser": "npm:^7.1.0"
"@sentry/react": "npm:^8.44.0"
"@toeverything/infra": "workspace:*"
"@types/react": "npm:^19.0.1"
@@ -4269,12 +4270,12 @@ __metadata:
languageName: node
linkType: hard
-"@capgo/inappbrowser@npm:^7.0.0":
- version: 7.2.16
- resolution: "@capgo/inappbrowser@npm:7.2.16"
+"@capgo/inappbrowser@npm:^7.1.0":
+ version: 7.1.6
+ resolution: "@capgo/inappbrowser@npm:7.1.6"
peerDependencies:
"@capacitor/core": ">=7.0.0"
- checksum: 10/3a28379f1d52a880f60355093f6d672730d3716e351c993a0d755218909f91ffad9d2126b34bfcfa9d3b1db28053ca607ecc698983717610dab22fd2cf207d69
+ checksum: 10/3c3062626ef511937682ee170514f5335841c1ee12c7a743ed6a908a1325dad31ed68294999204e500978fc5a06b501193e66410f3d3dc09da3d42ad09320f09
languageName: node
linkType: hard