Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Hide the mobile bottom bar before opening the keyboard https://github.com/siyuan-note/siyuan/issues/19095

Daniel2e142ce2cfa0
diff --git a/app/src/mobile/util/mobileAppUtil.test.ts b/app/src/mobile/util/mobileAppUtil.test.ts
index 62e35e1e5a..a06fae5791 100644
--- a/app/src/mobile/util/mobileAppUtil.test.ts
+++ b/app/src/mobile/util/mobileAppUtil.test.ts
@@ -1,6 +1,6 @@
import {describe, it} from "node:test";
import * as assert from "node:assert/strict";
-import {canInput} from "./mobileAppUtil";
+import {callMobileAppShowKeyboard, canInput} from "./mobileAppUtil";
const createElement = (options: {
tagName?: string,
@@ -50,3 +50,36 @@ describe("mobile input detection", () => {
assert.equal(canInput(wysiwygElement), false);
});
});
+
+describe("mobile app keyboard", () => {
+ it("notifies listeners before requesting the Android keyboard", () => {
+ const originalWindow = globalThis.window;
+ const calls: string[] = [];
+ const testWindow = new EventTarget() as Window & typeof globalThis;
+ Object.assign(testWindow, {
+ JSAndroid: {
+ showKeyboard() {
+ calls.push("keyboard");
+ },
+ },
+ });
+ testWindow.addEventListener("siyuan-mobile-keyboard-change", ((event: CustomEvent<boolean>) => {
+ assert.equal(event.detail, true);
+ calls.push("change");
+ }) as EventListener);
+ Object.defineProperty(globalThis, "window", {
+ configurable: true,
+ value: testWindow,
+ });
+
+ try {
+ callMobileAppShowKeyboard();
+ assert.deepEqual(calls, ["change", "keyboard"]);
+ } finally {
+ Object.defineProperty(globalThis, "window", {
+ configurable: true,
+ value: originalWindow,
+ });
+ }
+ });
+});
diff --git a/app/src/mobile/util/mobileAppUtil.ts b/app/src/mobile/util/mobileAppUtil.ts
index 22db45b517..5027bf6b81 100644
--- a/app/src/mobile/util/mobileAppUtil.ts
+++ b/app/src/mobile/util/mobileAppUtil.ts
@@ -10,6 +10,7 @@ export const armKeyboardLock = () => {
export const callMobileAppShowKeyboard = () => {
armKeyboardLock();
+ window.dispatchEvent(new CustomEvent("siyuan-mobile-keyboard-change", {detail: true}));
if (window.JSAndroid && window.JSAndroid.showKeyboard) {
window.JSAndroid.showKeyboard();