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

Commit dd1c5f4b authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[flexiglass] Use a key for every value saved by rememberSession" into main

parents b3e07300 dbfeb709
Loading
Loading
Loading
Loading
+16 −15
Original line number Diff line number Diff line
@@ -101,7 +101,6 @@ import com.android.internal.jank.InteractionJankMonitor.CUJ_NOTIFICATION_SHADE_S
import com.android.systemui.common.ui.compose.windowinsets.LocalScreenCornerRadius
import com.android.systemui.res.R
import com.android.systemui.scene.session.ui.composable.SaveableSession
import com.android.systemui.scene.session.ui.composable.rememberSession
import com.android.systemui.scene.session.ui.composable.sessionCoroutineScope
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.shade.ui.composable.ShadeHeader
@@ -306,13 +305,13 @@ fun ContentScope.NotificationScrollingStack(
    onEmptySpaceClick: (() -> Unit)? = null,
) {
    val composeViewRoot = LocalView.current
    val coroutineScope = shadeSession.sessionCoroutineScope()
    val coroutineScope = shadeSession.sessionCoroutineScope(key = "NotificationScrollingStack")
    val density = LocalDensity.current
    val screenCornerRadius = LocalScreenCornerRadius.current
    val scrimCornerRadius = dimensionResource(R.dimen.notification_scrim_corner_radius)
    val scrimBackgroundColor = MaterialTheme.colorScheme.surface
    val scrollState =
        shadeSession.rememberSaveableSession(saver = ScrollState.Saver, key = null) {
        shadeSession.rememberSaveableSession(saver = ScrollState.Saver, key = "ScrollState") {
            ScrollState(initial = 0)
        }
    val syntheticScroll = viewModel.syntheticScroll.collectAsStateWithLifecycle(0f)
@@ -327,7 +326,7 @@ fun ContentScope.NotificationScrollingStack(
     * notifications, this can exceed the space available on screen to show notifications, at which
     * point the notification stack should become scrollable.
     */
    val stackHeight = remember { mutableIntStateOf(0) }
    val stackHeight = shadeSession.rememberSession(key = "StackHeight") { mutableIntStateOf(0) }

    /**
     * Space available for the notification stack on the screen. These bounds don't scroll off the
@@ -344,7 +343,7 @@ fun ContentScope.NotificationScrollingStack(
    // When fully expanded (scrimOffset = minScrimOffset), its top bound is at minScrimStartY,
    // which is equal to the height of the Shade Header. Thus, when the scrim is fully expanded, the
    // entire height of the scrim is visible on screen.
    val scrimOffset = shadeSession.rememberSession { Animatable(0f) }
    val scrimOffset = shadeSession.rememberSession(key = "ScrimOffset") { Animatable(0f) }

    // set the bounds to null when the scrim disappears
    DisposableEffect(Unit) { onDispose { viewModel.onScrimBoundsChanged(null) } }
@@ -369,7 +368,8 @@ fun ContentScope.NotificationScrollingStack(
    // The top y bound of the IME.
    val imeTop = remember { mutableFloatStateOf(0f) }

    val shadeScrollState by remember {
    val shadeScrollState by
        shadeSession.rememberSession(key = "ShadeScrollState") {
            derivedStateOf {
                ShadeScrollState(
                    // we are not scrolled to the top unless the scroll position is zero,
@@ -462,6 +462,7 @@ fun ContentScope.NotificationScrollingStack(

    val scrimNestedScrollConnection =
        shadeSession.rememberSession(
            key = "ScrimConnection",
            scrimOffset,
            minScrimTop,
            viewModel.isCurrentGestureOverscroll,
+8 −5
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ fun Session.SessionDisposableEffect(
    key: String? = null,
    effect: DisposableEffectScope.() -> DisposableEffectResult,
) {
    rememberSession(inputs, key) {
    rememberSession(inputs = inputs, key = key) {
        object : RememberObserver {

            var onDispose: DisposableEffectResult? = null
@@ -137,12 +137,15 @@ fun Session.SessionDisposableEffect(
 */
@Composable
fun Session.sessionCoroutineScope(
    getContext: () -> CoroutineContext = { EmptyCoroutineContext }
    key: String? = null,
    getContext: () -> CoroutineContext = { EmptyCoroutineContext },
): CoroutineScope {
    val effectContext: CoroutineContext = rememberCompositionContext().effectCoroutineContext
    val job = rememberSession { Job() }
    SessionDisposableEffect { onDispose { job.cancel() } }
    return rememberSession { CoroutineScope(effectContext + job + getContext()) }
    val job = rememberSession(key = "Job(key=$key)") { Job() }
    SessionDisposableEffect(key = "DisposeJob(key=$key)") { onDispose { job.cancel() } }
    return rememberSession(key = "CoroutineScope(key=$key)") {
        CoroutineScope(effectContext + job + getContext())
    }
}

/**