Skip to content

Commit c64e024

Browse files
committed
Send message to gd.games iframe when keyboard opens
1 parent 99873e5 commit c64e024

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

newIDE/app/src/MainFrame/EditorContainers/HomePage/PlaySection/GamesPlatformFrame.js

+18
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
homepageMobileMenuHeight,
99
} from '../HomePageMenuBar';
1010
import Paper from '../../../../UI/Paper';
11+
import { useSoftKeyboardBottomOffset } from '../../../../UI/MobileSoftKeyboard';
1112

1213
export const GAMES_PLATFORM_IFRAME_ID = 'games-platform-frame';
1314

@@ -36,9 +37,11 @@ type Props = {|
3637
|};
3738

3839
const GamesPlatformFrame = ({ initialGameId, loaded, visible }: Props) => {
40+
const iframeRef = React.useRef<?HTMLIFrameElement>(null);
3941
const gdevelopTheme = React.useContext(GDevelopThemeContext);
4042
const paletteType = gdevelopTheme.palette.type;
4143
const { isMobile, isMediumScreen } = useResponsiveWindowSize();
44+
const softKeyboardBottomOffset = useSoftKeyboardBottomOffset();
4245

4346
// Use a ref to store the initial game id, as we don't want to trigger a re-render
4447
// when the game id changes.
@@ -68,6 +71,20 @@ const GamesPlatformFrame = ({ initialGameId, loaded, visible }: Props) => {
6871
[loaded, initialGameId]
6972
);
7073

74+
React.useEffect(
75+
() => {
76+
if (!iframeRef.current) return;
77+
iframeRef.current.contentWindow.postMessage(
78+
{
79+
type: 'keyboardOffset',
80+
value: softKeyboardBottomOffset - homepageMobileMenuHeight,
81+
},
82+
'*'
83+
);
84+
},
85+
[softKeyboardBottomOffset]
86+
);
87+
7188
const titleBarAndToolbarHeight = isMobile ? 0 : 37 + 40;
7289
const containerTop = isMobile
7390
? 0 // Always top of the screen on small screens.
@@ -98,6 +115,7 @@ const GamesPlatformFrame = ({ initialGameId, loaded, visible }: Props) => {
98115
}}
99116
>
100117
<iframe
118+
ref={iframeRef}
101119
id={GAMES_PLATFORM_IFRAME_ID}
102120
src={src}
103121
allow="autoplay; fullscreen *; geolocation; microphone; camera; midi; monetization; xr-spatial-tracking; gamepad; gyroscope; accelerometer; xr; keyboard-map *; focus-without-user-activation *; screen-wake-lock; clipboard-read; clipboard-write; web-share"

0 commit comments

Comments
 (0)