From 67301221083a794a909420721a256af25a39956b Mon Sep 17 00:00:00 2001 From: aki-chang-dev <7299525+aki-chang-dev@users.noreply.github.com> Date: Wed, 12 Feb 2025 11:28:56 +0000 Subject: [PATCH] feat(android): implement capacitor/keyboard plugin (#10125) --- .../apps/android/App/app/capacitor.build.gradle | 1 + .../src/main/java/app/affine/pro/MainActivity.kt | 4 +++- .../apps/android/App/capacitor.settings.gradle | 3 +++ packages/frontend/apps/android/package.json | 3 ++- packages/frontend/apps/android/src/app.tsx | 15 +++++++++++++++ yarn.lock | 11 ++++++----- 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/packages/frontend/apps/android/App/app/capacitor.build.gradle b/packages/frontend/apps/android/App/app/capacitor.build.gradle index aebef209b..464e4cd44 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 8d50a9f2f..bbba5edb9 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 ac95c8a87..46eaad7d0 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 2deec0992..31886c97e 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 26bd12581..0407839ef 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 526d67de6..d5ec44d7c 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