diff --git a/src/core/features/editor/components/rich-text-editor/rich-text-editor.ts b/src/core/features/editor/components/rich-text-editor/rich-text-editor.ts index c611b2e4d..9a27b95d1 100644 --- a/src/core/features/editor/components/rich-text-editor/rich-text-editor.ts +++ b/src/core/features/editor/components/rich-text-editor/rich-text-editor.ts @@ -1045,7 +1045,7 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterViewInit, * Window resized. */ protected async windowResized(): Promise { - await CoreDomUtils.waitForResizeDone(); + await CoreWait.waitForResizeDone(); this.isPhone = CoreScreen.isMobile; this.maximizeEditorSize(); diff --git a/src/core/services/utils/dom.ts b/src/core/services/utils/dom.ts index 5090f66c8..68ff56d09 100644 --- a/src/core/services/utils/dom.ts +++ b/src/core/services/utils/dom.ts @@ -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 { - 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); } /** diff --git a/src/core/singletons/dom.ts b/src/core/singletons/dom.ts index 07c0c425e..8f962cc87 100644 --- a/src/core/singletons/dom.ts +++ b/src/core/singletons/dom.ts @@ -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); diff --git a/src/core/singletons/wait.ts b/src/core/singletons/wait.ts index d2a633464..72e6c6ea8 100644 --- a/src/core/singletons/wait.ts +++ b/src/core/singletons/wait.ts @@ -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 { + 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); + } + } /**