Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(ui): keep chat composer pinned to bottom under desktop pinch-zoom (#653)

Call Whited58b649885a4
diff --git a/ui/src/lib/softKeyboard.ts b/ui/src/lib/softKeyboard.ts
index 5e7f990ac..e0f393e9f 100644
--- a/ui/src/lib/softKeyboard.ts
+++ b/ui/src/lib/softKeyboard.ts
@@ -49,7 +49,14 @@ const isTouchDevice = typeof navigator !== 'undefined' && navigator.maxTouchPoin
export function isSoftKeyboardOpen(): boolean {
if (!isTouchDevice || typeof window === 'undefined' || !window.visualViewport) return false;
- return restingHeight - window.visualViewport.height > KEYBOARD_MIN_DELTA;
+ const vv = window.visualViewport;
+ // vv.height (and so the resting-height delta) is in CSS px, which pinch-zoom
+ // shrinks by ~1/scale — but the OS keyboard occupies a fixed slice of the physical
+ // screen, so at scale > 1 the measured delta reads ~keyboardCssPx/scale and can dip
+ // under the fixed threshold while the keyboard is genuinely open (e.g. iPad: zoom,
+ // then focus a field). Multiply the delta back up by scale to compare in unzoomed
+ // CSS px; at scale 1 this is a no-op, so non-zoomed behavior is unchanged.
+ return (restingHeight - vv.height) * vv.scale > KEYBOARD_MIN_DELTA;
}
// True on devices with an on-screen keyboard (touch). Callers gate on this to
diff --git a/ui/src/lib/useViewportHeightVar.ts b/ui/src/lib/useViewportHeightVar.ts
index d11b24f11..6dfb2fc06 100644
--- a/ui/src/lib/useViewportHeightVar.ts
+++ b/ui/src/lib/useViewportHeightVar.ts
@@ -1,4 +1,5 @@
import { useEffect } from 'react';
+import { isSoftKeyboardOpen, isTouchCapableDevice } from './softKeyboard';
// iOS Safari keeps the layout viewport (and 100dvh) at full height when the
// virtual keyboard opens — only the VISUAL viewport shrinks — so a bottom-pinned
@@ -12,17 +13,41 @@ import { useEffect } from 'react';
// (the mobile shell is a static locked column instead, see AppShell/index.css).
// The ONLY consumer is the md+ chat (iPad / phone-landscape), which uses the
// desktop layout and so cannot use the mobile body-lock; sizing that chat to the
-// visual viewport keeps its composer above the soft keyboard. Refs:
+// visual viewport keeps its composer above the soft keyboard.
+//
+// Gated so it tracks ONLY the soft keyboard: (1) touch devices — non-touch desktops
+// have no keyboard, so the var must stay at its 100dvh default; (2) skip a
+// keyboard-less pinch-zoom — trackpad/gesture zoom ALSO shrinks visualViewport.height
+// (with scale > 1), and mirroring that would drag the bottom-pinned composer up off
+// the bottom (worse the more you zoom). Zoom can coexist with the keyboard though
+// (iPad: zoom first, then focus the composer), and there the inset is still needed,
+// so we keep applying it whenever isSoftKeyboardOpen() and only bail on a zoom with
+// no keyboard. Refs:
// https://www.bram.us/2021/09/13/prevent-items-from-being-hidden-underneath-the-virtual-keyboard-by-means-of-the-virtualkeyboard-api/
// https://dev.to/franciscomoretti/fix-mobile-keyboard-overlap-with-visualviewport-3a4a
export function useViewportHeightVar(): void {
useEffect(() => {
+ // Non-touch desktops have no soft keyboard, so this var must never move there;
+ // bailing out also makes the chat immune to trackpad pinch-zoom (which would
+ // otherwise shrink --app-vvh and lift the composer). CSS keeps its 100dvh
+ // default — a layout-viewport unit pinch-zoom can't touch.
+ if (!isTouchCapableDevice()) return;
const vv = window.visualViewport;
// No visualViewport (older browsers / SSR) → CSS keeps its 100dvh default.
if (!vv) return;
let raf = 0;
const apply = () => {
raf = 0;
+ // Touch devices can pinch-zoom too (iPad, touch laptops), which also shrinks
+ // vv.height with scale > 1. A keyboard-less zoom must NOT drive the inset (it
+ // would lift the composer off the bottom), so drop the override and fall back
+ // to 100dvh. But zoom and the keyboard can be up together (zoom, then focus the
+ // composer) — then we still need the inset, so only bail when the keyboard is
+ // closed; isSoftKeyboardOpen() is scale-aware, so it still fires while zoomed.
+ if (vv.scale > 1 && !isSoftKeyboardOpen()) {
+ document.documentElement.style.removeProperty('--app-vvh');
+ return;
+ }
document.documentElement.style.setProperty('--app-vvh', `${Math.round(vv.height)}px`);
};
const schedule = () => {