From c1621f62b009b97ac5948ebf6237e3a38066ac2c Mon Sep 17 00:00:00 2001 From: Igor Demin Date: Tue, 8 Feb 2022 15:27:41 +0300 Subject: [PATCH] Draw the first frame before window is visible Fixes https://github.com/JetBrains/compose-jb/issues/1794 If the first frame is too long to draw (> 500ms), users should make their apps asynchronous and draw UI gradully in multiple frames without blocking the UI thread for too long in single frame # Conflicts: # compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/window/TestUtils.kt # compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/window/dialog/DialogTest.kt # compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/window/window/WindowTest.kt --- .../compose/ui/window/dialog/DialogTest.kt | 31 +++++++++++++++++++ .../compose/ui/window/window/WindowTest.kt | 30 ++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/window/dialog/DialogTest.kt b/compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/window/dialog/DialogTest.kt index 7f1f30f279a2f..5380a00e83df9 100644 --- a/compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/window/dialog/DialogTest.kt +++ b/compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/window/dialog/DialogTest.kt @@ -552,4 +552,35 @@ class DialogTest { exitApplication() } + + + @Test(timeout = 30000) + fun `should draw before dialog is visible`() = runApplicationTest { + var isComposed = false + var isDrawn = false + var isVisibleOnFirstComposition = false + var isVisibleOnFirstDraw = false + + launchTestApplication { + Dialog(onCloseRequest = ::exitApplication) { + if (!isComposed) { + isVisibleOnFirstComposition = window.isVisible + isComposed = true + } + + Canvas(Modifier.fillMaxSize()) { + if (!isDrawn) { + isVisibleOnFirstDraw = window.isVisible + isDrawn = true + } + } + } + } + + awaitIdle() + assertThat(isVisibleOnFirstComposition).isFalse() + assertThat(isVisibleOnFirstDraw).isFalse() + + exitTestApplication() + } } \ No newline at end of file diff --git a/compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/window/window/WindowTest.kt b/compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/window/window/WindowTest.kt index 315e3620dbfa0..9fdf112748fc6 100644 --- a/compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/window/window/WindowTest.kt +++ b/compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/window/window/WindowTest.kt @@ -558,4 +558,34 @@ class WindowTest { assertThat(isApplicationEffectEnded).isTrue() assertThat(isWindowEffectEnded).isTrue() } + + @Test(timeout = 30000) + fun `should draw before window is visible`() = runApplicationTest { + var isComposed = false + var isDrawn = false + var isVisibleOnFirstComposition = false + var isVisibleOnFirstDraw = false + + launchTestApplication { + Window(onCloseRequest = ::exitApplication) { + if (!isComposed) { + isVisibleOnFirstComposition = window.isVisible + isComposed = true + } + + Canvas(Modifier.fillMaxSize()) { + if (!isDrawn) { + isVisibleOnFirstDraw = window.isVisible + isDrawn = true + } + } + } + } + + awaitIdle() + assertThat(isVisibleOnFirstComposition).isFalse() + assertThat(isVisibleOnFirstDraw).isFalse() + + exitTestApplication() + } } \ No newline at end of file