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

Commit 9238e3d

Browse files
fix(#327): workaround to resize ion-app
1 parent b89e0d6 commit 9238e3d

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

studio/src/global/app-dev.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,54 @@ setupDeckGoConfig({
5050
prismComponentsUrl: 'https://raw.githubusercontent.com/PrismJS/prism/886698d5b759ef46162a5723a2493f97c689dc94/components.json',
5151
gifExampleSrc: 'https://media.giphy.com/media/xUA7baWfTjfHGLZc3e/200w_d.gif'
5252
});
53+
54+
// https://github.com/deckgo/deckdeckgo/issues/327
55+
// https://github.com/ionic-team/ionic/issues/19065
56+
57+
const hack = () => {
58+
const ionApp = document.querySelector('ion-app');
59+
60+
if (ionApp) {
61+
window.requestAnimationFrame(() => {
62+
ionApp.style.height = '100%';
63+
window.requestAnimationFrame(() => {
64+
ionApp.style.height = '';
65+
});
66+
});
67+
}
68+
};
69+
70+
let resizerObserver;
71+
72+
document.addEventListener('DOMContentLoaded', () => {
73+
if (!window) {
74+
return;
75+
}
76+
77+
if ('ResizeObserver' in window) {
78+
const ResizeObserver = (window as any).ResizeObserver;
79+
resizerObserver = new ResizeObserver(hack);
80+
resizerObserver.observe(document.documentElement);
81+
} else {
82+
window.addEventListener('keyboardWillShow', hack);
83+
window.addEventListener('keyboardWillHide', hack);
84+
window.addEventListener('resize', hack);
85+
}
86+
});
87+
88+
window.addEventListener('unload', () => {
89+
if (!window) {
90+
return;
91+
}
92+
93+
if ('ResizeObserver' in window) {
94+
if (resizerObserver) {
95+
resizerObserver.unobserve(document.documentElement);
96+
resizerObserver.disconnect();
97+
}
98+
} else {
99+
window.removeEventListener('keyboardWillShow', hack);
100+
window.removeEventListener('keyboardWillHide', hack);
101+
window.removeEventListener('resize', hack);
102+
}
103+
});

studio/src/global/app.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,55 @@ log.apply(console, ['%cDeckDeckGo', 'color: #3880ff;font-size:2rem;font-weight:
5757
log.apply(console, ['%cHey there, interested by our code? Lucky you, we are open source :)', 'color: black;font-size:1rem;font-weight: 300;']);
5858
log.apply(console, ['%cCome say hi and contribute to our project on Github', 'color: black;font-size:1rem;font-weight: 300;']);
5959
log.apply(console, ['%chttps://github.com/deckgo/deckdeckgo', 'font-size:1rem;font-weight: 300;']);
60+
61+
62+
// https://github.com/deckgo/deckdeckgo/issues/327
63+
// https://github.com/ionic-team/ionic/issues/19065
64+
65+
const hack = () => {
66+
const ionApp = document.querySelector('ion-app');
67+
68+
if (ionApp) {
69+
window.requestAnimationFrame(() => {
70+
ionApp.style.height = '100%';
71+
window.requestAnimationFrame(() => {
72+
ionApp.style.height = '';
73+
});
74+
});
75+
}
76+
};
77+
78+
let resizerObserver;
79+
80+
document.addEventListener('DOMContentLoaded', () => {
81+
if (!window) {
82+
return;
83+
}
84+
85+
if ('ResizeObserver' in window) {
86+
const ResizeObserver = (window as any).ResizeObserver;
87+
resizerObserver = new ResizeObserver(hack);
88+
resizerObserver.observe(document.documentElement);
89+
} else {
90+
window.addEventListener('keyboardWillShow', hack);
91+
window.addEventListener('keyboardWillHide', hack);
92+
window.addEventListener('resize', hack);
93+
}
94+
});
95+
96+
window.addEventListener('unload', () => {
97+
if (!window) {
98+
return;
99+
}
100+
101+
if ('ResizeObserver' in window) {
102+
if (resizerObserver) {
103+
resizerObserver.unobserve(document.documentElement);
104+
resizerObserver.disconnect();
105+
}
106+
} else {
107+
window.removeEventListener('keyboardWillShow', hack);
108+
window.removeEventListener('keyboardWillHide', hack);
109+
window.removeEventListener('resize', hack);
110+
}
111+
});

0 commit comments

Comments
 (0)