From a880573afb0d3df2e1989fd42e1016dac9ad254c Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 26 Oct 2026 05:14:04 +0000 Subject: [PATCH] Keep widgets until the app drawer slides over them Opening the drawer unmarked the widget slots, so the native widget views were hidden at once, before the drawer had painted. Now the widgets stay put under the drawer and the shell clips them above its edge each frame as it slides down, hiding them once it covers the screen. On close they come back only after the page has painted without the drawer. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01NFvkdqdrRGWHGq1LUzzK7L --- .../java/dev/ultra/launcher/MainActivity.java | 44 ++++++++++++++++++- web/index.html | 28 +++++++++++- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/android/app/src/main/java/dev/ultra/launcher/MainActivity.java b/android/app/src/main/java/dev/ultra/launcher/MainActivity.java index 4c2e215..aee22e5 100644 --- a/android/app/src/main/java/dev/ultra/launcher/MainActivity.java +++ b/android/app/src/main/java/dev/ultra/launcher/MainActivity.java @@ -96,7 +96,8 @@ public class MainActivity extends Activity { static final int REQ_BIND = 1, REQ_CONFIGURE = 2; private WebView web; - private FrameLayout widgetLayer; + private CoverLayer widgetLayer; + private long coverRequest; // the latest coverWidgets, so a stale uncover is dropped private AppWidgetManager widgets; private AppWidgetHost widgetHost; private final Map widgetViews = new HashMap<>(); @@ -173,7 +174,7 @@ public class MainActivity extends Activity { }); widgetViews.clear(); widgetSizes.clear(); - widgetLayer = new FrameLayout(this); + widgetLayer = new CoverLayer(this); FrameLayout root = new FrameLayout(this); root.addView(web); root.addView(widgetLayer); @@ -604,6 +605,30 @@ public class MainActivity extends Activity { } } + /** + * Holds the widget views. The app drawer slides down over the page, so the widgets + * must be hidden above its edge: cover(top) clips them (and their touches) above top + * px, -1 hides them all, 0 shows them all. + */ + static final class CoverLayer extends FrameLayout { + private int top; + + CoverLayer(Context c) { super(c); } + + void cover(int y) { + if (y == top) return; + top = y; + setVisibility(y < 0 ? View.INVISIBLE : View.VISIBLE); + setClipBounds(y > 0 ? new Rect(0, y, Math.max(getWidth(), 1), Math.max(getHeight(), y + 1)) : null); + } + + @Override + public boolean dispatchTouchEvent(MotionEvent ev) { + if (top != 0 && ev.getActionMasked() == MotionEvent.ACTION_DOWN && (top < 0 || ev.getY() < top)) return false; + return super.dispatchTouchEvent(ev); + } + } + static final class WidgetView extends AppWidgetHostView { private final MainActivity home; private final int id; @@ -779,6 +804,21 @@ public class MainActivity extends Activity { main.post(() -> MainActivity.this.placeWidgets(json)); } + /** The drawer covers the page down to y (CSS px); -1 is all of it, 0 none. */ + @JavascriptInterface public void coverWidgets(int y) { + main.post(() -> { + long n = ++coverRequest; + if (y != 0) { widgetLayer.cover(y < 0 ? -1 : Math.round(y * getResources().getDisplayMetrics().density)); return; } + // The drawer is gone from the page; show the widgets once the page has + // painted without it, so they don't flash over it for a frame. + web.postVisualStateCallback(n, new WebView.VisualStateCallback() { + @Override public void onComplete(long requestId) { + if (requestId == coverRequest) widgetLayer.cover(0); + } + }); + }); + } + @JavascriptInterface public String widgetLimits(int id) { return MainActivity.this.widgetLimits(id); } diff --git a/web/index.html b/web/index.html index 7ee8812..067159a 100644 --- a/web/index.html +++ b/web/index.html @@ -49,7 +49,10 @@ s.classList.contains("resizing") ? 1 : 0]; // its body moves it instead of taking touches }); const j = JSON.stringify(slots); - if (j !== placed) { placed = j; host.placeWidgets(j); } + // The drawer unmarks the slots, but the home screen under it doesn't move, so the + // widgets stay where they were and cover() hides them as it slides over them. + const underDrawer = document.querySelector(".drawer") && !document.querySelector(".sheet-overlay"); + if (j !== placed && !underDrawer) { placed = j; host.placeWidgets(j); } // Keep the system's edge swipes (back) off the resize handles. const handles = JSON.stringify([...document.querySelectorAll(".resize-handle")].map((h) => { const r = h.getBoundingClientRect(); @@ -59,6 +62,27 @@ }; let excluded = "[]"; + // Native widgets sit above the page, so the drawer can't cover them by itself. While it + // slides down the shell hides them above its bottom edge each frame (coverWidgets(y), + // CSS px; -1 once it covers the screen), so they stay until the drawer reaches them. + // The edge is reported a little ahead (by its speed), since the shell trails a frame. + let coverY = 0, coverLast = 0, coverLoop = false; + const cover = () => { + const d = document.querySelector(".drawer"); + let y = 0; + if (d) { + const b = d.getBoundingClientRect().bottom; + y = b >= innerHeight - 1 ? -1 : Math.max(0, Math.ceil(b + 2 * Math.max(0, b - coverLast))); + coverLast = b; + if (y >= innerHeight) y = innerHeight - 1; + } else coverLast = 0; + if (y !== coverY) { coverY = y; host.coverWidgets?.(y); } + if (d && y !== -1 && !coverLoop) { + coverLoop = true; + requestAnimationFrame(() => { coverLoop = false; cover(); }); + } + }; + // 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. @@ -119,7 +143,7 @@ let ready = false; // the grid code below exists and app is mounted const app = await mount("#app", "./app.wasm", { - onRender: () => { fillIcons(); place(); watchDrawer(); if (ready) measureGrid(); }, + onRender: () => { fillIcons(); place(); cover(); watchDrawer(); if (ready) measureGrid(); }, imports: ({ strs }) => ({ launch: (h) => host.launch(strs[h]), app_info: (h) => host.appInfo(strs[h]),