Skip to content

Commit 969d3b8

Browse files
committed
fix viewport on mobile for gamepad and dashboard
1 parent 59aae65 commit 969d3b8

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

addons/selkies-dashboard/src/components/Sidebar.jsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,20 @@ function Sidebar({ isOpen }) {
583583
};
584584
}, []);
585585

586+
useEffect(() => {
587+
const setRealViewportHeight = () => {
588+
const vh = window.innerHeight * 0.01;
589+
document.documentElement.style.setProperty('--vh', `${vh}px`);
590+
};
591+
window.addEventListener('resize', setRealViewportHeight);
592+
window.addEventListener('orientationchange', setRealViewportHeight);
593+
setRealViewportHeight();
594+
return () => {
595+
window.removeEventListener('resize', setRealViewportHeight);
596+
window.removeEventListener('orientationchange', setRealViewportHeight);
597+
};
598+
}, []);
599+
586600
const { t, raw } = translator;
587601
const sendKeyEvent = (type, key, code, modifierState) => {
588602
const event = new KeyboardEvent(type, {

addons/selkies-dashboard/src/styles/Overlay.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
top: 0;
9090
left: 0;
9191
width: 280px;
92-
height: 100vh;
92+
height: calc(var(--vh, 1vh) * 100);
9393
background-color: var(--sidebar-bg);
9494
box-shadow: 2px 0 5px var(--sidebar-shadow);
9595
transform: translateX(-100%);

addons/universal-touch-gamepad/universalTouchGamepad.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
const MAX_AXES = 4;
88
const PREVIEW_SCALE = 0.15;
99

10-
const SAFE_AREA_PADDING = { top: 10, right: 15, bottom: 20, left: 15 };
10+
const SAFE_AREA_PADDING = { top: 10, right: 15, bottom: 10, left: 15 };
1111
const HIT_TEST_SLOP = 10;
1212

1313
const STICK_TAP_DURATION_THRESHOLD = 250;
@@ -53,6 +53,14 @@
5353
</svg>
5454
`;
5555

56+
function setRealViewportHeight() {
57+
const vh = window.innerHeight * 0.01;
58+
document.documentElement.style.setProperty('--vh', `${vh}px`);
59+
}
60+
window.addEventListener('resize', setRealViewportHeight);
61+
window.addEventListener('orientationchange', setRealViewportHeight);
62+
setRealViewportHeight();
63+
5664
let hostAnchorElement = null;
5765
let currentProfileName = 'eightBit';
5866
let isGamepadVisible = false;
@@ -673,7 +681,7 @@
673681
isProfileSelectorVisible = true;
674682
profileSelectorOverlayElement = document.createElement('div');
675683
Object.assign(profileSelectorOverlayElement.style, {
676-
position: 'fixed', top: '0', left: '0', width: '100vw', height: '100vh',
684+
position: 'fixed', top: '0', left: '0', width: '100vw', height: 'calc(var(--vh, 1vh) * 100)',
677685
backgroundColor: 'rgba(0, 0, 0, 0.75)',
678686
display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center',
679687
zIndex: '2147483640', pointerEvents: 'auto',
@@ -767,7 +775,7 @@
767775
gamepadControlsOverlayElement.id = 'universal-touch-gamepad-controls-overlay';
768776
Object.assign(gamepadControlsOverlayElement.style, {
769777
position: 'fixed', top: '0', left: '0',
770-
width: '100vw', height: '100vh',
778+
width: '100vw', height: 'calc(var(--vh, 1vh) * 100)',
771779
zIndex: '2000',
772780
pointerEvents: 'none',
773781
overflow: 'hidden'

0 commit comments

Comments
 (0)