Fix Android keyboard gap: don't double-offset the composer
Device logs showed Android's interactive-widget=resizes-content already shrinks the layout viewport to above the keyboard (innerHeight 800->472 for a 328px keyboard), yet the app also lifted the composer by --kb=328 → a keyboard-height white gap. Now gate the manual --kb lift to iOS only (WKWebView doesn't resize); on Android keep --kb=0 and just toggle kb-open so --sab collapses and the composer sits flush to the keyboard. Also removes the temporary kbdiag logging. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
1ece8e1061
commit
a8e0f549d4
1 file changed
+15
-9
+15
-9
@@ -1343,15 +1343,21 @@ function twemojify(_el){ /* native emoji: nothing to do */ }</script>
|
||||
var KB=C.Plugins&&C.Plugins.Keyboard;
|
||||
if(p==='ios' && KB && KB.setAccessoryBarVisible){ try{ KB.setAccessoryBarVisible({ isVisible:false }); }catch(_){} } // hide the grey iOS input accessory bar (up/down chevrons + Done) above the keyboard — iOS-only, no-op elsewhere
|
||||
if(KB && KB.addListener){
|
||||
KB.addListener('keyboardWillShow', function(info){ var raw=(info&&info.keyboardHeight)||0; var kb = raw>window.innerHeight ? raw/(window.devicePixelRatio||1) : raw; setKb(kb); });
|
||||
KB.addListener('keyboardWillHide', function(){ setKb(0); });
|
||||
KB.addListener('keyboardDidHide', function(){ setKb(0); }); // belt-and-suspenders: some close paths only fire Did*
|
||||
// TEMP kbdiag (remove after diagnosing the Android repeat-open gap): logs the metrics that tell us whether
|
||||
// the WebView resizes (interactive-widget) vs relies on --kb, and any residual across open #1 vs #2.
|
||||
var _kbn=0, _cs=function(){ return getComputedStyle(document.documentElement).getPropertyValue('--kb').trim(); };
|
||||
KB.addListener('keyboardWillShow', function(info){ _kbn++; console.log('[kbdiag] willShow#'+_kbn+' kbH='+((info&&info.keyboardHeight)||0)+' innerH='+window.innerHeight+' clientH='+document.documentElement.clientHeight+' vvH='+(window.visualViewport?Math.round(window.visualViewport.height):'-')+' preKb='+_cs()); });
|
||||
if(KB.addListener){ KB.addListener('keyboardDidShow', function(info){ console.log('[kbdiag] didShow kbH='+((info&&info.keyboardHeight)||0)+' innerH='+window.innerHeight+' clientH='+document.documentElement.clientHeight+' vvH='+(window.visualViewport?Math.round(window.visualViewport.height):'-')+' curKb='+_cs()+' kbOpen='+document.body.classList.contains('kb-open')); }); }
|
||||
KB.addListener('keyboardDidHide', function(){ console.log('[kbdiag] didHide innerH='+window.innerHeight+' clientH='+document.documentElement.clientHeight+' vvH='+(window.visualViewport?Math.round(window.visualViewport.height):'-')+' curKb='+_cs()); });
|
||||
if(p==='ios'){
|
||||
// iOS WKWebView does NOT resize for the keyboard (it ignores interactive-widget) → lift the composer
|
||||
// manually by the reported keyboard height.
|
||||
KB.addListener('keyboardWillShow', function(info){ var raw=(info&&info.keyboardHeight)||0; var kb = raw>window.innerHeight ? raw/(window.devicePixelRatio||1) : raw; setKb(kb); });
|
||||
KB.addListener('keyboardWillHide', function(){ setKb(0); });
|
||||
KB.addListener('keyboardDidHide', function(){ setKb(0); }); // belt-and-suspenders: some close paths only fire Did*
|
||||
} else {
|
||||
// Android: interactive-widget=resizes-content already SHRINKS the layout viewport to sit above the keyboard
|
||||
// (device log: innerHeight 800→472 for a 328px keyboard), so the composer is already positioned. Applying
|
||||
// the --kb lift too DOUBLED it → a keyboard-height white gap. Keep --kb=0 here; only toggle kb-open so --sab
|
||||
// (nav-bar inset) collapses and the composer sits flush to the keyboard.
|
||||
KB.addListener('keyboardWillShow', function(){ r.style.setProperty('--kb','0px'); document.body.classList.add('kb-open'); var b=document.getElementById('msgs'); if(b && (b.scrollHeight-b.scrollTop-b.clientHeight)<400) b.scrollTop=b.scrollHeight; });
|
||||
KB.addListener('keyboardWillHide', function(){ r.style.setProperty('--kb','0px'); document.body.classList.remove('kb-open'); });
|
||||
KB.addListener('keyboardDidHide', function(){ document.body.classList.remove('kb-open'); });
|
||||
}
|
||||
}
|
||||
}catch(_){} })();
|
||||
// Browser / iOS home-screen PWA (NO Capacitor Keyboard plugin): lift the composer above the on-screen
|
||||
|
||||
Reference in new issue
Block a user