MOBILE-3814 core: Use waitForResizeDone on onWindowResize listener

main
Pau Ferrer Ocaña 2022-03-19 15:57:15 +01:00
parent f31ee78cfb
commit fd1e5ee0eb
4 changed files with 7 additions and 31 deletions

View File

@ -360,7 +360,7 @@ export class AddonQtypeDdImageOrTextQuestion {
}); });
this.resizeListener = CoreDomUtils.onWindowResize(() => { this.resizeListener = CoreDomUtils.onWindowResize(() => {
this.windowResized(); this.repositionDragsForQuestion();
}); });
} }
@ -679,15 +679,6 @@ export class AddonQtypeDdImageOrTextQuestion {
} }
} }
/**
* Window resized.
*/
async windowResized(): Promise<void> {
await CoreDomUtils.waitForResizeDone();
this.repositionDragsForQuestion();
}
} }
/** /**

View File

@ -611,7 +611,7 @@ export class AddonQtypeDdMarkerQuestion {
}); });
this.resizeListener = CoreDomUtils.onWindowResize(() => { this.resizeListener = CoreDomUtils.onWindowResize(() => {
this.windowResized(); this.redrawDragsAndDrops();
}); });
} }
@ -879,15 +879,6 @@ export class AddonQtypeDdMarkerQuestion {
} }
} }
/**
* Window resized.
*/
async windowResized(): Promise<void> {
await CoreDomUtils.waitForResizeDone();
this.redrawDragsAndDrops();
}
} }
/** /**

View File

@ -212,7 +212,7 @@ export class AddonQtypeDdwtosQuestion {
this.positionDragItems(); this.positionDragItems();
this.resizeListener = CoreDomUtils.onWindowResize(() => { this.resizeListener = CoreDomUtils.onWindowResize(() => {
this.windowResized(); this.positionDragItems();
}); });
} }
@ -513,15 +513,6 @@ export class AddonQtypeDdwtosQuestion {
}); });
} }
/**
* Window resized.
*/
async windowResized(): Promise<void> {
await CoreDomUtils.waitForResizeDone();
this.positionDragItems();
}
} }
/** /**

View File

@ -276,7 +276,9 @@ export class CoreDomUtilsProvider {
* @return Event observer to call off when finished. * @return Event observer to call off when finished.
*/ */
onWindowResize(resizeFunction: (ev?: Event) => void, debounceDelay = 20): CoreEventObserver { 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); resizeFunction(ev);
}, debounceDelay); }, 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. * 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 windowWidth Initial window width.
* @param windowHeight Initial window height. * @param windowHeight Initial window height.