Focus the drawer's search and raise the keyboard when the drawer opens
Swiping down to the app drawer puts the cursor in its search box. A WebView won't show the keyboard for a script focus(), so the shell does it through new Android.showKeyboard/hideKeyboard bridge calls; closing the drawer hides it again. Pick mode (adding apps) stays keyboard-free. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0169wSWnZqnXBsJKMPAiCCNG
This commit is contained in:
3 files changed
+39
-1
No files matched your search
@@ -35,6 +35,7 @@ import android.view.View;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.view.Window;
|
||||
import android.view.WindowInsets;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.webkit.JavascriptInterface;
|
||||
import android.webkit.RenderProcessGoneDetail;
|
||||
import android.webkit.WebResourceRequest;
|
||||
@@ -751,6 +752,22 @@ public class MainActivity extends Activity {
|
||||
HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING));
|
||||
}
|
||||
|
||||
/** The page focused the drawer's search box; show the keyboard for it. */
|
||||
@JavascriptInterface public void showKeyboard() {
|
||||
main.postDelayed(() -> {
|
||||
web.requestFocus();
|
||||
InputMethodManager imm = getSystemService(InputMethodManager.class);
|
||||
if (imm != null) imm.showSoftInput(web, InputMethodManager.SHOW_IMPLICIT);
|
||||
}, 50);
|
||||
}
|
||||
|
||||
@JavascriptInterface public void hideKeyboard() {
|
||||
main.post(() -> {
|
||||
InputMethodManager imm = getSystemService(InputMethodManager.class);
|
||||
if (imm != null) imm.hideSoftInputFromWindow(web.getWindowToken(), 0);
|
||||
});
|
||||
}
|
||||
|
||||
@JavascriptInterface public void openSettings() {
|
||||
main.post(() -> startIntent(new Intent(Settings.ACTION_SETTINGS)));
|
||||
}
|
||||
|
||||
@@ -77,6 +77,7 @@ const BASE = process.env.BASE || "http://localhost:8000";
|
||||
await swipe(200, 500);
|
||||
await p.waitForSelector(".drawer", { timeout: 2000 });
|
||||
assert.equal(await p.$$eval("[data-wid]", (ws) => ws.length), 0);
|
||||
assert.ok(await p.$eval(".drawer input", (i) => i === document.activeElement), "opening the drawer focuses its search");
|
||||
await p.fill(".drawer input", "ma"); await settle();
|
||||
assert.deepEqual(await p.$$eval(".apps .name", (ns) => ns.map((n) => n.textContent)), ["Gmail", "Maps"]);
|
||||
await p.press(".drawer input", "Enter"); await settle();
|
||||
|
||||
+21
-1
@@ -32,6 +32,8 @@
|
||||
openSettings: () => toast("Open system settings"),
|
||||
pickWallpaper: () => toast("Pick a wallpaper"),
|
||||
openRecents: () => toast("Show open windows"),
|
||||
showKeyboard: () => {},
|
||||
hideKeyboard: () => {},
|
||||
haptic: () => navigator.vibrate?.(10),
|
||||
};
|
||||
if (!window.Android) document.documentElement.classList.add("demo");
|
||||
@@ -54,6 +56,24 @@
|
||||
};
|
||||
let excluded = "[]";
|
||||
|
||||
// Opening the drawer puts the cursor in its search box and raises the keyboard
|
||||
// (a WebView won't show it for a focus() the user didn't tap, so the shell does).
|
||||
// Picking apps to add is for scrolling, so that stays keyboard-free.
|
||||
let drawerOpen = false;
|
||||
const watchDrawer = () => {
|
||||
const d = document.querySelector(".drawer");
|
||||
if (!!d === drawerOpen) return;
|
||||
drawerOpen = !!d;
|
||||
if (d) {
|
||||
if (d.classList.contains("picking")) return;
|
||||
d.querySelector(".drawer-head input")?.focus({ preventScroll: true });
|
||||
host.showKeyboard?.();
|
||||
} else {
|
||||
document.activeElement?.blur?.();
|
||||
host.hideKeyboard?.();
|
||||
}
|
||||
};
|
||||
|
||||
// Icons: each <img class="icon" data-icon=KEY> gets its src from here. On a phone the
|
||||
// shell draws icons on its own thread and hands them back as data: URIs in batches
|
||||
// (ultraIcons), so the WebView never loads icons through request interception.
|
||||
@@ -95,7 +115,7 @@
|
||||
window.ultraIcons = gotIcons; // the shell calls this before ultraHome exists, too
|
||||
|
||||
const app = await mount("#app", "./app.wasm", {
|
||||
onRender: () => { fillIcons(); place(); },
|
||||
onRender: () => { fillIcons(); place(); watchDrawer(); },
|
||||
imports: ({ strs }) => ({
|
||||
launch: (h) => host.launch(strs[h]),
|
||||
app_info: (h) => host.appInfo(strs[h]),
|
||||
|
||||
Reference in new issue
Block a user