diff --git a/server/public/home.html b/server/public/home.html index bef100a..1a25816 100644 --- a/server/public/home.html +++ b/server/public/home.html @@ -1112,7 +1112,7 @@
- // juggling here — we only tag so CSS can make small native-only tweaks if needed. (function(){ try{ var C=window.Capacitor; if(!C||!C.isNativePlatform||!C.isNativePlatform()) return; var p=(C.getPlatform&&C.getPlatform())||''; var r=document.documentElement; r.classList.add('native-app'); if(p) r.classList.add('native-'+p); - // Keyboard: with resize:none the WebView never resizes, so we raise the composer by the keyboard height. - // The plugin reports that height in DEVICE PIXELS on some builds, but CSS wants points — so a raw value - // bigger than the screen's point height is divided by devicePixelRatio. This normalization makes it land - // exactly on the keyboard regardless of unit. - // Measured on-device: the plugin's reported height puts the composer ~2x too high, so scale it. This is - // a single tunable number — if the composer isn't flush on the keyboard, nudge KB_FACTOR up/down. - var KB_FACTOR=0.52; - function bzKbHeight(raw){ raw=raw||0; var dpr=window.devicePixelRatio||1; var norm = raw > window.innerHeight ? raw/dpr : raw; return Math.round(norm*KB_FACTOR); } + // Keyboard — DEVICE-INDEPENDENT: the real keyboard overlap is (layout viewport height - visible viewport + // height), read from the VisualViewport API. No per-device factor. We prefer that; only if the WebView + // doesn't reflect the keyboard in VisualViewport do we fall back to the plugin's reported height. + function kbFromVV(){ var vv=window.visualViewport; if(!vv) return 0; return Math.max(0, Math.round(document.documentElement.clientHeight - vv.height - vv.offsetTop)); } + function applyKb(px){ px=Math.max(0,Math.round(px)); r.style.setProperty('--kb',px+'px'); document.body.classList.toggle('kb-open',px>4); if(px>4){ var b=document.getElementById('msgs'); if(b) b.scrollTop=b.scrollHeight; } } + // TEMP one-time debug readout (remove once logic is locked): shows the raw signals at the top of screen. + var dbg=document.createElement('div'); var lastRaw=null; + dbg.style.cssText='position:fixed;left:0;right:0;top:0;z-index:2147483647;background:rgba(0,0,0,.82);color:#0f0;font:11px/1.35 monospace;padding:3px 6px;text-align:center;pointer-events:none;'; + function rd(){ var vv=window.visualViewport; dbg.textContent='kbRaw='+(lastRaw==null?'-':Math.round(lastRaw))+' innerH='+window.innerHeight+' clientH='+document.documentElement.clientHeight+' vvH='+(vv?Math.round(vv.height):'-')+' vvTop='+(vv?Math.round(vv.offsetTop):'-')+' dpr='+window.devicePixelRatio+' -> vvKb='+kbFromVV(); } + if(document.body){ document.body.appendChild(dbg); } else { document.addEventListener('DOMContentLoaded', function(){ document.body.appendChild(dbg); }); } + if(window.visualViewport){ ['resize','scroll'].forEach(function(ev){ window.visualViewport.addEventListener(ev, function(){ var k=kbFromVV(); if(k>20) applyKb(k); rd(); }); }); } var KB=C.Plugins&&C.Plugins.Keyboard; if(KB && KB.addListener){ - KB.addListener('keyboardWillShow', function(info){ var h=bzKbHeight(info&&info.keyboardHeight); r.style.setProperty('--kb', h+'px'); document.body.classList.add('kb-open'); var b=document.getElementById('msgs'); if(b) requestAnimationFrame(function(){ b.scrollTop=b.scrollHeight; }); }); - KB.addListener('keyboardWillHide', function(){ r.style.setProperty('--kb','0px'); document.body.classList.remove('kb-open'); }); + KB.addListener('keyboardWillShow', function(info){ lastRaw=info&&info.keyboardHeight; rd(); setTimeout(function(){ var k=kbFromVV(); if(k>20){ applyKb(k); } else { var raw=lastRaw||0, dpr=window.devicePixelRatio||1; applyKb(raw>window.innerHeight?raw/dpr:raw); } rd(); }, 60); }); + KB.addListener('keyboardWillHide', function(){ lastRaw=0; applyKb(0); rd(); }); } + rd(); }catch(_){} })();