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

Commit d1aecc73 authored by Darrell Shi's avatar Darrell Shi Committed by Android (Google) Code Review
Browse files

Merge "Prevent unnecessary recompositions on communal container" into main

parents 109ce60c 1b92f8fe
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()