MOBILE-4616 chore: Move waitForResizeDone to CoreWait
parent
6303769f0c
commit
ab7b69c262
|
@ -1045,7 +1045,7 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterViewInit,
|
|||
* Window resized.
|
||||
*/
|
||||
protected async windowResized(): Promise<void> {
|
||||
await CoreDomUtils.waitForResizeDone();
|
||||
await CoreWait.waitForResizeDone();
|
||||
this.isPhone = CoreScreen.isMobile;
|
||||
|
||||
this.maximizeEditorSize();
|
||||
|
|
|
@ -1715,24 +1715,11 @@ export class CoreDomUtilsProvider {
|
|||
* @param windowHeight Initial window height.
|
||||
* @param retries Number of retries done.
|
||||
* @returns Promise resolved when done.
|
||||
*
|
||||
* @deprecated since 4.5. Use CoreWait.waitForResizeDone instead.
|
||||
*/
|
||||
async waitForResizeDone(windowWidth?: number, windowHeight?: number, retries = 0): Promise<void> {
|
||||
if (!CorePlatform.isIOS()) {
|
||||
return; // Only wait in iOS.
|
||||
}
|
||||
|
||||
windowWidth = windowWidth || window.innerWidth;
|
||||
windowHeight = windowHeight || window.innerHeight;
|
||||
|
||||
if (windowWidth != window.innerWidth || windowHeight != window.innerHeight || retries >= 10) {
|
||||
// Window size changed or max number of retries reached, stop.
|
||||
return;
|
||||
}
|
||||
|
||||
// Wait a bit and try again.
|
||||
await CoreWait.wait(50);
|
||||
|
||||
return this.waitForResizeDone(windowWidth, windowHeight, retries+1);
|
||||
return CoreWait.waitForResizeDone(windowWidth, windowHeight, retries);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -13,10 +13,10 @@
|
|||
// limitations under the License.
|
||||
|
||||
import { CoreCancellablePromise } from '@classes/cancellable-promise';
|
||||
import { CoreDomUtils } from '@services/utils/dom';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreEventObserver } from '@singletons/events';
|
||||
import { CorePlatform } from '@services/platform';
|
||||
import { CoreWait } from './wait';
|
||||
|
||||
/**
|
||||
* Singleton with helper functions for dom.
|
||||
|
@ -214,7 +214,7 @@ export class CoreDom {
|
|||
*/
|
||||
static onWindowResize(resizeFunction: (ev?: Event) => void, debounceDelay = 20): CoreEventObserver {
|
||||
const resizeListener = CoreUtils.debounce(async (ev?: Event) => {
|
||||
await CoreDomUtils.waitForResizeDone();
|
||||
await CoreWait.waitForResizeDone();
|
||||
|
||||
resizeFunction(ev);
|
||||
}, debounceDelay);
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
// limitations under the License.
|
||||
|
||||
import { CoreCancellablePromise } from '@classes/cancellable-promise';
|
||||
import { CorePlatform } from '@services/platform';
|
||||
|
||||
/**
|
||||
* Singleton with helper functions to wait.
|
||||
|
@ -83,6 +84,34 @@ export class CoreWait {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 CoreDom.onWindowResize to check window resize event.
|
||||
*
|
||||
* @param windowWidth Initial window width.
|
||||
* @param windowHeight Initial window height.
|
||||
* @param retries Number of retries done.
|
||||
* @returns Promise resolved when done.
|
||||
*/
|
||||
static async waitForResizeDone(windowWidth?: number, windowHeight?: number, retries = 0): Promise<void> {
|
||||
if (!CorePlatform.isIOS()) {
|
||||
return; // Only wait in iOS.
|
||||
}
|
||||
|
||||
windowWidth = windowWidth || window.innerWidth;
|
||||
windowHeight = windowHeight || window.innerHeight;
|
||||
|
||||
if (windowWidth != window.innerWidth || windowHeight != window.innerHeight || retries >= 10) {
|
||||
// Window size changed or max number of retries reached, stop.
|
||||
return;
|
||||
}
|
||||
|
||||
// Wait a bit and try again.
|
||||
await CoreWait.wait(50);
|
||||
|
||||
return CoreWait.waitForResizeDone(windowWidth, windowHeight, retries+1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue