Skip to content

Commit

Permalink
Draw the first frame before window is visible
Browse files Browse the repository at this point in the history
Fixes JetBrains/compose-multiplatform#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
  • Loading branch information
igordmn committed Mar 28, 2022
1 parent 247a118 commit c1621f6
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

0 comments on commit c1621f6

Please sign in to comment.