Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 85dd3026 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere
Browse files

Mark scenes as ready in a LaunchedEffect

This CL marks seen ready once they have been fully composed, laidout and
drawn once, in a LaunchedEffect. Previously, we were doing that after
drawing all scenes, but this assumed a drawing order which is not
necessarily correct when using layers (e.g. when using scrollable
lists).

Bug: 291053742
Test: Manual, there is no flicker when going from lockscreen to shade
anymore.

Change-Id: Ic6a336196a8892eeb713ebe71cef013b6f88ecb3
parent 113c97fd
Loading
Loading
Loading
Loading
+5 −17
Original line number Diff line number Diff line
@@ -158,26 +158,14 @@ internal class SceneTransitionLayoutImpl(
                    BackHandler { onChangeScene(backScene) }
                }

                Box(
                    Modifier.drawWithContent {
                        drawContent()

                        // At this point, all scenes in scenesToCompose are fully laid out so they
                        // are marked as ready. This is necessary because the animation code needs
                        // to know the position and size of the elements in each scenes they are in,
                        // so [readyScenes] will be used to decide whether the transition is ready
                        // (see isTransitionReady() below).
                        //
                        // We can't do that in a DisposableEffect or SideEffect because those are
                        // run between composition and layout. LaunchedEffect could work and might
                        // be better, but it looks like launched effects run a frame later than this
                        // code so doing this here seems better for performance.
                        scenesToCompose.fastForEach { readyScenes[it.key] = true }
                    }
                ) {
                Box {
                    scenesToCompose.fastForEach { scene ->
                        val key = scene.key
                        key(key) {
                            // Mark this scene as ready once it has been composed, laid out and
                            // drawn the first time. We have to do this in a LaunchedEffect here
                            // because DisposableEffect runs between composition and layout.
                            LaunchedEffect(key) { readyScenes[key] = true }
                            DisposableEffect(key) { onDispose { readyScenes.remove(key) } }

                            scene.Content(