|
8 | 8 | homepageMobileMenuHeight,
|
9 | 9 | } from '../HomePageMenuBar';
|
10 | 10 | import Paper from '../../../../UI/Paper';
|
| 11 | +import { useSoftKeyboardBottomOffset } from '../../../../UI/MobileSoftKeyboard'; |
11 | 12 |
|
12 | 13 | export const GAMES_PLATFORM_IFRAME_ID = 'games-platform-frame';
|
13 | 14 |
|
@@ -36,9 +37,11 @@ type Props = {|
|
36 | 37 | |};
|
37 | 38 |
|
38 | 39 | const GamesPlatformFrame = ({ initialGameId, loaded, visible }: Props) => {
|
| 40 | + const iframeRef = React.useRef<?HTMLIFrameElement>(null); |
39 | 41 | const gdevelopTheme = React.useContext(GDevelopThemeContext);
|
40 | 42 | const paletteType = gdevelopTheme.palette.type;
|
41 | 43 | const { isMobile, isMediumScreen } = useResponsiveWindowSize();
|
| 44 | + const softKeyboardBottomOffset = useSoftKeyboardBottomOffset(); |
42 | 45 |
|
43 | 46 | // Use a ref to store the initial game id, as we don't want to trigger a re-render
|
44 | 47 | // when the game id changes.
|
@@ -68,6 +71,20 @@ const GamesPlatformFrame = ({ initialGameId, loaded, visible }: Props) => {
|
68 | 71 | [loaded, initialGameId]
|
69 | 72 | );
|
70 | 73 |
|
| 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 | + |
71 | 88 | const titleBarAndToolbarHeight = isMobile ? 0 : 37 + 40;
|
72 | 89 | const containerTop = isMobile
|
73 | 90 | ? 0 // Always top of the screen on small screens.
|
@@ -98,6 +115,7 @@ const GamesPlatformFrame = ({ initialGameId, loaded, visible }: Props) => {
|
98 | 115 | }}
|
99 | 116 | >
|
100 | 117 | <iframe
|
| 118 | + ref={iframeRef} |
101 | 119 | id={GAMES_PLATFORM_IFRAME_ID}
|
102 | 120 | src={src}
|
103 | 121 | 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