Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit e3a7a93

Browse files
fix: workaround to resize ion-app
1 parent 799199c commit e3a7a93

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import './scripts/actions.js';
2626
import './scripts/menu.js';
2727
import './scripts/history.js';
2828
import './scripts/fullscreen.js';
29+
import './scripts/resize.js';
2930

3031
import { defineCustomElements as ionicElements } from '@ionic/core/loader';
3132
ionicElements(window);

src/scripts/resize.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// https://github.com/deckgo/deckdeckgo/issues/327
2+
// https://github.com/ionic-team/ionic/issues/19065#issuecomment-521370741
3+
4+
const hack = () => {
5+
const ionApp = document.querySelector('ion-app');
6+
7+
if (ionApp) {
8+
window.requestAnimationFrame(() => {
9+
ionApp.style.height = '100%';
10+
window.requestAnimationFrame(() => {
11+
ionApp.style.height = '';
12+
});
13+
});
14+
}
15+
};
16+
17+
let resizerObserver;
18+
19+
document.addEventListener('DOMContentLoaded', () => {
20+
if (!window) {
21+
return;
22+
}
23+
24+
if ('ResizeObserver' in window) {
25+
const ResizeObserver = window.ResizeObserver;
26+
resizerObserver = new ResizeObserver(hack);
27+
resizerObserver.observe(document.documentElement);
28+
} else {
29+
window.addEventListener('keyboardWillShow', hack);
30+
window.addEventListener('keyboardWillHide', hack);
31+
window.addEventListener('resize', hack);
32+
}
33+
});
34+
35+
window.addEventListener('unload', () => {
36+
if (!window) {
37+
return;
38+
}
39+
40+
if ('ResizeObserver' in window) {
41+
console.log('here', resizerObserver);
42+
if (resizerObserver) {
43+
resizerObserver.unobserve(document.documentElement);
44+
resizerObserver.disconnect();
45+
}
46+
} else {
47+
window.removeEventListener('keyboardWillShow', hack);
48+
window.removeEventListener('keyboardWillHide', hack);
49+
window.removeEventListener('resize', hack);
50+
}
51+
});

0 commit comments

Comments
 (0)