Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(play): keep the world chat input above the phone keyboard

nirholasa58905777b67
diff --git a/src/game/coincommunities.css b/src/game/coincommunities.css
index c0e45b078..98364e602 100644
--- a/src/game/coincommunities.css
+++ b/src/game/coincommunities.css
@@ -35,6 +35,10 @@
half-dead. Anchor bottom-docked controls with these instead of bare px.
They resolve to 0px on hardware without insets, so desktop is unchanged. */
--cc-safe-b: env(safe-area-inset-bottom, 0px);
+ /* Height of the strip the on-screen keyboard is covering, published by
+ CoinCommunities._trackSoftKeyboard from visualViewport. 0px whenever no
+ keyboard is up, so bottom-docked controls sit where they always did. */
+ --cc-kb: 0px;
--cc-safe-l: env(safe-area-inset-left, 0px);
--cc-safe-r: env(safe-area-inset-right, 0px);
}
@@ -868,7 +872,7 @@ body.is-zen #cc-photo-btn:hover, body.is-zen #cc-photo-btn:focus-visible { opaci
/* chat sidebar — dockable, minimizable, persistent log */
#cc-chat {
- position: fixed; right: calc(14px + var(--cc-safe-r)); bottom: calc(14px + var(--cc-safe-b));
+ position: fixed; right: calc(14px + var(--cc-safe-r)); bottom: calc(14px + var(--cc-safe-b) + var(--cc-kb));
width: min(340px, 82vw);
max-height: min(60vh, 520px); z-index: 23;
display: flex; flex-direction: column; overflow: hidden;
@@ -1107,7 +1111,7 @@ body.is-zen #cc-photo-btn:hover, body.is-zen #cc-photo-btn:focus-visible { opaci
/* Chat: docked bottom-right, narrower so its left edge clears the joystick.
Above the emote tray so the input always receives taps. */
#cc-chat {
- left: auto; right: calc(10px + var(--cc-safe-r)); bottom: calc(10px + var(--cc-safe-b));
+ left: auto; right: calc(10px + var(--cc-safe-r)); bottom: calc(10px + var(--cc-safe-b) + var(--cc-kb));
width: min(58vw, 280px); max-height: 42vh; z-index: 24;
}
@@ -1115,7 +1119,7 @@ body.is-zen #cc-photo-btn:hover, body.is-zen #cc-photo-btn:focus-visible { opaci
collapsed chat pill and clear of the joystick. The expanded chat (higher z)
covers it — collapse chat to emote, which is the natural one-or-the-other. */
#cc-emotes {
- left: auto; right: calc(10px + var(--cc-safe-r)); bottom: calc(58px + var(--cc-safe-b));
+ left: auto; right: calc(10px + var(--cc-safe-r)); bottom: calc(58px + var(--cc-safe-b) + var(--cc-kb));
transform: none; z-index: 23;
max-width: calc(100vw - 150px); overflow-x: auto; -webkit-overflow-scrolling: touch;
padding: 6px; scrollbar-width: none;
@@ -1125,7 +1129,7 @@ body.is-zen #cc-photo-btn:hover, body.is-zen #cc-photo-btn:focus-visible { opaci
/* Reactions: row above emotes on mobile, same right-dock zone */
#cc-reactions {
- left: auto; right: calc(10px + var(--cc-safe-r)); bottom: calc(104px + var(--cc-safe-b));
+ left: auto; right: calc(10px + var(--cc-safe-r)); bottom: calc(104px + var(--cc-safe-b) + var(--cc-kb));
transform: none; z-index: 22;
max-width: calc(100vw - 150px); overflow-x: auto; -webkit-overflow-scrolling: touch;
padding: 4px 5px; scrollbar-width: none;
diff --git a/src/game/coincommunities.js b/src/game/coincommunities.js
index 5d5ffce77..7a13c8113 100644
--- a/src/game/coincommunities.js
+++ b/src/game/coincommunities.js
@@ -824,6 +824,42 @@ export class CoinCommunities {
window.addEventListener('resize', () => this._onResize());
this._watchDevicePixelRatio();
this._bindContextLoss();
+ this._trackSoftKeyboard();
+ }
+
+ // Keep bottom-docked HUD controls above the on-screen keyboard.
+ //
+ // The HUD is `position: fixed`, which anchors to the LAYOUT viewport. When a
+ // phone keyboard opens it shrinks the VISUAL viewport instead, so the layout
+ // viewport never changes and the chat input the player is typing into sits
+ // calmly underneath the keyboard, invisible. `vh` units have the same blind
+ // spot, which is why swapping in dvh does not fix a fixed element.
+ //
+ // visualViewport is the only API that reports the covered strip. Publish it as
+ // --cc-kb and let the bottom-docked rules add it to their offset, so the chat
+ // (and the emote/reaction rows stacked above it) ride up with the keyboard and
+ // drop back when it closes. Desktop and any browser without visualViewport keep
+ // --cc-kb at 0px and are untouched.
+ _trackSoftKeyboard() {
+ const vv = window.visualViewport;
+ if (!vv) return;
+ const root = document.documentElement;
+ this._onKeyboard = () => {
+ // The strip of layout viewport the keyboard (and any pinch-zoom offset)
+ // is covering. Never negative: an over-scrolled URL bar can report a
+ // visual viewport TALLER than the layout one, which would otherwise
+ // yank the HUD downward off-screen.
+ const covered = Math.max(0, window.innerHeight - vv.height - vv.offsetTop);
+ // Sub-pixel churn on every scroll frame would thrash layout for no
+ // visible gain; round and only write when it actually moved.
+ const px = Math.round(covered);
+ if (px === this._kbPx) return;
+ this._kbPx = px;
+ root.style.setProperty('--cc-kb', `${px}px`);
+ };
+ vv.addEventListener('resize', this._onKeyboard);
+ vv.addEventListener('scroll', this._onKeyboard);
+ this._onKeyboard();
}
// A browser may take the WebGL context away at any time. On phones it is the
@@ -1959,6 +1995,15 @@ export class CoinCommunities {
removeEventListener('focus', this._onResume);
this._onResume = null;
}
+ if (this._onKeyboard) {
+ window.visualViewport?.removeEventListener('resize', this._onKeyboard);
+ window.visualViewport?.removeEventListener('scroll', this._onKeyboard);
+ this._onKeyboard = null;
+ this._kbPx = 0;
+ // Leaving the world must not strand a keyboard offset on <html>: the
+ // lobby renders under the same :root and would sit shifted up.
+ document.documentElement.style.removeProperty('--cc-kb');
+ }
if (this.net) { this.net.destroy(); this.net = null; }
clearTimeout(this._announceTimer);
if (this.vehicles) { this.vehicles.dispose(); this.vehicles = null; }