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

Commit 40e53a42 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere
Browse files

Split SceneScope.MovableElement with SceneSope.Element (1/2)

This CL splits SceneScope.MovableElement() into .MovableElement() and
.Element(). These 2 functions now need to be used to declare animated
shared values. The old way of declaring animated values was removed.

With this CL, declaring an element (movable or not) with animated values
looks like this:

Element(key, modifier) { // or MovableElement(...)
  val animatedDp by animateElementDpAsState(targetValue, valueKey)

  content {
    Box(Modifier.offset { IntOffset(0, animatedDp.roundToPx()) }) {
      ...
    }
  }
}

It is a bit more verbose than before, but as explained in
b/317026105#comment3 we have to do this for MovableElement given that
the shared animate values need to be composed separately from the
element content.

Bug: 317026105
Test: PlatformComposeSceneTransitionLayoutTests
Flag: N/A
Change-Id: Ic842c4c6a0c66083830d74f03086408a5436b104
parent e09d2004
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ class AmbientIndicationSection @Inject constructor() {
            key = AmbientIndicationElementKey,
            modifier = modifier,
        ) {
            content {
                Box(
                    modifier = Modifier.fillMaxWidth().background(Color.Green),
                ) {
@@ -47,5 +48,6 @@ class AmbientIndicationSection @Inject constructor() {
            }
        }
    }
}

private val AmbientIndicationElementKey = ElementKey("AmbientIndication")
+23 −19
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ constructor(
            key = if (isStart) StartButtonElementKey else EndButtonElementKey,
            modifier = modifier,
        ) {
            content {
                Shortcut(
                    viewId = if (isStart) R.id.start_button else R.id.end_button,
                    viewModel = if (isStart) viewModel.startButton else viewModel.endButton,
@@ -90,6 +91,7 @@ constructor(
                )
            }
        }
    }

    @Composable
    fun SceneScope.IndicationArea(
@@ -99,6 +101,7 @@ constructor(
            key = IndicationAreaElementKey,
            modifier = modifier.shortcutPadding(),
        ) {
            content {
                IndicationArea(
                    indicationAreaViewModel = indicationAreaViewModel,
                    alphaViewModel = alphaViewModel,
@@ -106,6 +109,7 @@ constructor(
                )
            }
        }
    }

    @Composable
    fun shortcutSizeDp(): DpSize {
+23 −19
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ constructor(
            key = ClockElementKey,
            modifier = modifier,
        ) {
            content {
                Box(
                    modifier =
                        Modifier.fillMaxWidth()
@@ -63,6 +64,7 @@ constructor(
                }
            }
        }
    }

    @Composable
    fun SceneScope.LargeClock(modifier: Modifier = Modifier) {
@@ -74,6 +76,7 @@ constructor(
            key = ClockElementKey,
            modifier = modifier,
        ) {
            content {
                Box(
                    modifier = Modifier.fillMaxWidth().background(Color.Blue),
                ) {
@@ -86,5 +89,6 @@ constructor(
            }
        }
    }
}

private val ClockElementKey = ElementKey("Clock")
+0 −1
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import com.android.compose.animation.scene.SceneScope
import com.android.systemui.notifications.ui.composable.NotificationStack
import com.android.systemui.statusbar.notification.stack.ui.viewmodel.NotificationsPlaceholderViewModel
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher

class NotificationSection
@Inject
+33 −27
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ constructor(
            key = StatusBarElementKey,
            modifier = modifier,
        ) {
            content {
                AndroidView(
                    factory = {
                        notificationPanelView.get().findViewById<View>(R.id.keyguard_header)?.let {
@@ -63,6 +64,7 @@ constructor(
                            object : ShadeViewStateProvider {
                                override val lockscreenShadeDragProgress: Float = 0f
                                override val panelViewExpandedHeight: Float = 0f

                                override fun shouldHeadsUpBeVisible(): Boolean {
                                    return false
                                }
@@ -76,7 +78,10 @@ constructor(
                                    null,
                                    false,
                                ) as KeyguardStatusBarView
                    componentFactory.build(view, provider).keyguardStatusBarViewController.init()
                        componentFactory
                            .build(view, provider)
                            .keyguardStatusBarViewController
                            .init()
                        view
                    },
                    modifier =
@@ -87,5 +92,6 @@ constructor(
            }
        }
    }
}

private val StatusBarElementKey = ElementKey("StatusBar")
Loading