当虚拟键盘在全屏显示模式下处于活动状态时,PWA 不会调整窗口大小
我正在开发一个 PWA,主要针对移动用户。据我所知,网络的默认行为是,当虚拟键盘处于活动状态时,窗口大小会相应调整。这对于网络上的移动设备和独立显示模式来说效果很好。在全屏模式下,当键盘处于活动状态时,窗口大小不会改变。这导致输入被隐藏在键盘后面。现在有人知道为什么会出现这种情况吗?或者是否有破解方法可以解决这个问题? (比如手动获取键盘的高度等)据我所知,该问题仅发生在 android chrome 上,ios safari 按预期工作。
I am developing a PWA, primarily targeting mobile users. The default behavior for the web, as far as I know it that, when the virtual keyboard is active, the window size adjusts accordingly. This works fine for mobile on the web and in standalone display mode. In fullscreen mode the window size does not change when the keyboard is active. That results in inputs beeing hidden behind the keyboard. Does anyone now why that is the case or if there is a hack to get around that? (Like getting the height of the keyboard manually, etc.) The issue only occurs on android chrome as far as I know, ios safari works as expected.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当 PWA 显示设置为全屏时,API 不允许视口根据输入事件进行调整,因此虚拟键盘将始终覆盖应用程序。有关更多详细信息,请参阅 Progressive Web-App Soft-全屏时键盘和导航栏重叠
最简单的解决方案是将其设置为独立。否则:
您可以执行的强制视口更新的一种通用 CSS 解决方法是使用 :focus-within,例如(注意,未广泛测试):
我们使用的更具体的解决方法是使用 Javascript 将 input_focus 类添加到 body 标记仅在焦点事件上特定适用的表单元素,然后使用 CSS 选择该元素并设置该元素的样式(绝对/固定)以浮动在键盘上方。
使用 jQuery 的简要示例:
JS
CSS
注意:如果使用 AJAX 动态加载 DOM 区域,请将 JS 包装在函数 & 中。每次 AJAX 完成加载时运行。
When the PWA Display is set to fullscreen, the API doesn't allow the viewport to adjust upon input events, so the virtual keyboard will always overlay the app. For more details see Progressive Web-App Soft-Keyboard and Nav Bar overlaps in Fullscreen
Simplest solution is to set it to standalone. Otherwise:
One generic CSS workaround you can do to enforce viewport updates is use :focus-within, for example (note, not broadly tested):
A more specific workaround we used was to use Javascript to add an input_focus class to the body tag for specific applicable form elements only on the focus event, then select that with CSS and style that element (absolute/fixed) to float above the keyboard.
Brief example of this with jQuery:
JS
CSS
Note: if areas of the DOM are loaded dynamically with AJAX, wrap the JS in a function & run each time the AJAX has finished loading.
这是一个 CSS 问题...通常是静态定位和/或静态高度值的结果。
尝试更新body标签的样式;将其位置设置为相对。
此外,有时所需要做的就是将应用程序包装器的高度更新为动态值,例如 100% 或 100vh。
This is a CSS issue... usually a result of static positioning and/or static height values.
Try updating the style of the body tag; setting its position to relative.
Also, sometimes all it takes is updating the app-wrapper's height to something dynamic like 100% or 100vh.