From fd1e5ee0ebdf9d657a3fe64774dda85b5f0f73ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Sat, 19 Mar 2022 15:57:15 +0100 Subject: [PATCH] MOBILE-3814 core: Use waitForResizeDone on onWindowResize listener --- .../qtype/ddimageortext/classes/ddimageortext.ts | 11 +---------- src/addons/qtype/ddmarker/classes/ddmarker.ts | 11 +---------- src/addons/qtype/ddwtos/classes/ddwtos.ts | 11 +---------- src/core/services/utils/dom.ts | 5 ++++- 4 files changed, 7 insertions(+), 31 deletions(-) diff --git a/src/addons/qtype/ddimageortext/classes/ddimageortext.ts b/src/addons/qtype/ddimageortext/classes/ddimageortext.ts index 5fd0cc61b..3d066d1f0 100644 --- a/src/addons/qtype/ddimageortext/classes/ddimageortext.ts +++ b/src/addons/qtype/ddimageortext/classes/ddimageortext.ts @@ -360,7 +360,7 @@ export class AddonQtypeDdImageOrTextQuestion { }); this.resizeListener = CoreDomUtils.onWindowResize(() => { - this.windowResized(); + this.repositionDragsForQuestion(); }); } @@ -679,15 +679,6 @@ export class AddonQtypeDdImageOrTextQuestion { } } - /** - * Window resized. - */ - async windowResized(): Promise { - await CoreDomUtils.waitForResizeDone(); - - this.repositionDragsForQuestion(); - } - } /** diff --git a/src/addons/qtype/ddmarker/classes/ddmarker.ts b/src/addons/qtype/ddmarker/classes/ddmarker.ts index e1a1ddc06..ab7350a80 100644 --- a/src/addons/qtype/ddmarker/classes/ddmarker.ts +++ b/src/addons/qtype/ddmarker/classes/ddmarker.ts @@ -611,7 +611,7 @@ export class AddonQtypeDdMarkerQuestion { }); this.resizeListener = CoreDomUtils.onWindowResize(() => { - this.windowResized(); + this.redrawDragsAndDrops(); }); } @@ -879,15 +879,6 @@ export class AddonQtypeDdMarkerQuestion { } } - /** - * Window resized. - */ - async windowResized(): Promise { - await CoreDomUtils.waitForResizeDone(); - - this.redrawDragsAndDrops(); - } - } /** diff --git a/src/addons/qtype/ddwtos/classes/ddwtos.ts b/src/addons/qtype/ddwtos/classes/ddwtos.ts index 9bb54147a..63c4fcc6c 100644 --- a/src/addons/qtype/ddwtos/classes/ddwtos.ts +++ b/src/addons/qtype/ddwtos/classes/ddwtos.ts @@ -212,7 +212,7 @@ export class AddonQtypeDdwtosQuestion { this.positionDragItems(); this.resizeListener = CoreDomUtils.onWindowResize(() => { - this.windowResized(); + this.positionDragItems(); }); } @@ -513,15 +513,6 @@ export class AddonQtypeDdwtosQuestion { }); } - /** - * Window resized. - */ - async windowResized(): Promise { - await CoreDomUtils.waitForResizeDone(); - - this.positionDragItems(); - } - } /** diff --git a/src/core/services/utils/dom.ts b/src/core/services/utils/dom.ts index 88215d904..5e1aed45e 100644 --- a/src/core/services/utils/dom.ts +++ b/src/core/services/utils/dom.ts @@ -276,7 +276,9 @@ export class CoreDomUtilsProvider { * @return Event observer to call off when finished. */ onWindowResize(resizeFunction: (ev?: Event) => void, debounceDelay = 20): CoreEventObserver { - const resizeListener = CoreUtils.debounce((ev?: Event) => { + const resizeListener = CoreUtils.debounce(async (ev?: Event) => { + await this.waitForResizeDone(); + resizeFunction(ev); }, debounceDelay); @@ -2153,6 +2155,7 @@ export class CoreDomUtilsProvider { /** * In iOS the resize event is triggered before the window size changes. Wait for the size to change. + * Use of this function is discouraged. Please use onWindowResize to check window resize event. * * @param windowWidth Initial window width. * @param windowHeight Initial window height.