TF-3911 Remove window event listeners to prevent memory leaks in Email View

This commit is contained in:
dab246
2025-08-05 23:29:11 +07:00
committed by Dat H. Pham
parent fd7e349929
commit 846c9c6583
2 changed files with 52 additions and 31 deletions
+16 -4
View File
@@ -286,7 +286,13 @@ class HtmlInteraction {
}, {
passive: false,
});
window.addEventListener('keydown', function(e) {
window.addEventListener('keydown', disableZoomControl);
window.addEventListener('pagehide', (event) => {
window.removeEventListener('keydown', disableZoomControl);
});
function disableZoomControl(event) {
if (event.metaKey || event.ctrlKey) {
switch (event.key) {
case '=':
@@ -295,7 +301,7 @@ class HtmlInteraction {
break;
}
}
});
}
</script>
''';
@@ -381,7 +387,13 @@ class HtmlInteraction {
static String scriptHandleIframeKeyboardListener(String viewId) => '''
<script type="text/javascript">
window.addEventListener('keydown', function (event) {
window.addEventListener('keydown', handleIframeKeydown);
window.addEventListener('pagehide', (event) => {
window.removeEventListener('keydown', handleIframeKeydown);
});
function handleIframeKeydown(event) {
const payload = {
view: '$viewId',
type: 'toDart: iframeKeydown',
@@ -390,7 +402,7 @@ class HtmlInteraction {
shift: event.shiftKey
};
window.parent.postMessage(JSON.stringify(payload), "*");
});
}
</script>
''';
}