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

Commit 1b92f8fe authored by Darrell Shi's avatar Darrell Shi
Browse files

Prevent unnecessary recompositions on communal container

This change addresses a performance regression that caused unnecessary
recompositions on the communal container when expanding and collapsing
the shade over the lockscreen. This was solved by moving the relevant
state changes to a lower, more specific composable level, making sure
that the recompositions only occur when the communal scene is present.

Test: verified communal container does not recompose when expanding and
      collapsing the shade over lockscreen
Test: verified touches on the blank spaces in the shade does not fall
      through to the communal scene
Test: verified pulling down the shade over communal scene causes the
      scene to blur correctly
Bug: 432615057
Flag: EXEMPT improve performance
Change-Id: I55eb81c329432119a0e62089e293a03d343088ef
parent 6266129d
Loading
Loading
Loading
Loading
+11 −11
Original line number Diff line number Diff line
@@ -240,7 +240,6 @@ fun CommunalContainer(
) {
    val coroutineScope = rememberCoroutineScope()
    val currentSceneKey: SceneKey by viewModel.currentScene.collectAsStateWithLifecycle()
    val touchesAllowed by viewModel.touchesAllowed.collectAsStateWithLifecycle()
    val backgroundType by
        viewModel.communalBackground.collectAsStateWithLifecycle(
            initialValue = CommunalBackgroundType.ANIMATED
@@ -252,9 +251,6 @@ fun CommunalContainer(
            canChangeScene = { toScene -> viewModel.canChangeScene(toScene) },
            transitions = if (viewModel.v2FlagEnabled()) sceneTransitionsV2 else sceneTransitions,
        )

    val isUiBlurred by viewModel.isUiBlurred.collectAsStateWithLifecycle()

    val detector = remember { CommunalSwipeDetector() }

    DisposableEffect(state) {
@@ -270,14 +266,12 @@ fun CommunalContainer(
        onDispose { viewModel.setTransitionState(null) }
    }

    val blurRadius = with(LocalDensity.current) { viewModel.blurRadiusPx.toDp() }

    val swipeFromHubInLandscape by
        viewModel.swipeFromHubInLandscape.collectAsStateWithLifecycle(false)

    SceneTransitionLayout(
        state = state,
        modifier = modifier.fillMaxSize().thenIf(isUiBlurred) { Modifier.blur(blurRadius) },
        modifier = modifier.fillMaxSize(),
        swipeSourceDetector = detector,
        swipeDetector = detector,
    ) {
@@ -314,6 +308,8 @@ fun CommunalContainer(
                        UserActionResult(CommunalScenes.Blank, CommunalTransitionKeys.SwipeUp),
                ),
        ) {
            val touchesAllowed by viewModel.touchesAllowed.collectAsStateWithLifecycle()

            CommunalScene(
                backgroundType = backgroundType,
                colors = colors,
@@ -321,13 +317,14 @@ fun CommunalContainer(
                ambientStatusBarSection = ambientStatusBarSection,
                viewModel = viewModel,
            )
        }
    }

    // Touches on the notification shade in blank areas fall through to the glanceable hub. When the
    // shade is showing, we block all touches in order to prevent this unwanted behavior.
            // Touches on the notification shade in blank areas fall through to the glanceable hub.
            // When the shade is showing, we block all touches in order to prevent this unwanted
            // behavior.
            Box(modifier = Modifier.fillMaxSize().allowGestures(touchesAllowed))
        }
    }
}

/** Scene containing the glanceable hub UI. */
@Composable
@@ -340,11 +337,14 @@ fun ContentScope.CommunalScene(
    modifier: Modifier = Modifier,
) {
    val isFocusable by viewModel.isFocusable.collectAsStateWithLifecycle(initialValue = false)
    val isBlurred by viewModel.isUiBlurred.collectAsStateWithLifecycle()
    val blurRadius = with(LocalDensity.current) { viewModel.blurRadiusPx.toDp() }

    Box(
        modifier =
            Modifier.element(Communal.Elements.Scrim)
                .fillMaxSize()
                .thenIf(isBlurred) { Modifier.blur(blurRadius) }
                .then(
                    if (isFocusable) {
                        Modifier.focusable()