Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Screen height on tablet vs keyboard #1162

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<link rel="icon" href="%BASE_URL%favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, interactive-widget=resizes-content" />
<meta name="theme-color" content="#6c4bc1" />
<title>micro:bit Python Editor</title>
<meta property="og:title" content="micro:bit Python Editor" />
Expand Down
5 changes: 3 additions & 2 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ body,
.WorkbenchContainer,
.Workbench {
width: 100%;
/* --ios-vvh set by VisualViewPortCSSVariables on iOS only. */
height: var(--ios-vvh, var(--webkit-vvh, 100vh));
/* --vvh set by VisualViewPortCSSVariables */
height: var(--vvh, var(--webkit-vvh, 100vh));
overflow: hidden;
}
body {
overflow: hidden;
Expand Down
31 changes: 17 additions & 14 deletions src/common/VisualViewportCSSVariables.tsx
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed since we are aiming to have the keyboard overlay the UI instead of having a shifting action bar

Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,31 @@ const isIOS = (): boolean =>

/**
* Maintains CSS variables for the visual viewport width and height.
* Use with fallbacks, e.g. var(--ios-vvh, 100vh)
* Use with fallbacks, e.g. var(--vvh, 100vh)
* https://developer.mozilla.org/en-US/docs/Web/API/Visual_Viewport_API
*
* This is important for iOS where we want to avoid the keyboard being
* drawn over the toolbar at the bottom.
*
* We skip it on other platforms and rely on the fallback.
*/
const VisualViewPortCSSVariables = () => {
const addStyleInnerText = (innerText: string) => {
let style = document.getElementById(styleId);
if (!style) {
style = document.head.appendChild(document.createElement("style"));
style.id = styleId;
}
style.innerText = innerText;
};

useEffect(() => {
// If we remove the iOS check then we should look carefully at resize performance.
if (!window.visualViewport || !isIOS()) {
// svh on Safari in iOS does not resize when virtual keyboard is present
if (CSS.supports("height: 100svh") && !isIOS) {
addStyleInnerText(":root { --vvh: 100svh }");
return;
}
microbit-grace marked this conversation as resolved.
Show resolved Hide resolved
if (!window.visualViewport) {
return;
}
microbit-grace marked this conversation as resolved.
Show resolved Hide resolved
const resizeHandler = () => {
const { width, height } = window.visualViewport ?? {};
let style = document.getElementById(styleId);
if (!style) {
style = document.head.appendChild(document.createElement("style"));
style.id = styleId;
}
style.innerText = `:root { --ios-vvw: ${width}px; --ios-vvh: ${height}px; }`;
addStyleInnerText(`:root { --vvw: ${width}px; --vvh: ${height}px; }`);
};
window.visualViewport.addEventListener("resize", resizeHandler);
resizeHandler();
Expand Down
Loading