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

Commit e67b2809 authored by Alejandro Nijamkin's avatar Alejandro Nijamkin Committed by Ale Nijamkin
Browse files

[flexiglass] Notification section in pure Compose.

Reuses existing work that uses a composable for the NSSL to redo how we
communicate the placement of the NSSL to the notification system.

This is using the same solution as what other Flexiglass scenes are
using.

Bug: 316211368
Test: turned on the legacy flag NSSL_DEBUG_LINES that renders a red
background and verified that it's properly placed in the hierarchy
between the smart space and the lock icon.
Test: posted notifications using the notifier app and saw them if I also
turned on FLEXI_NOTIFS in SceneContainerFlagsExtension.
Flag: ACONFIG com.android.systemui.scene_container DEVELOPMENT

Change-Id: Icab4b9cf4ff3a6a5cc249444b803c51ab99de252
parent d98c52f2
Loading
Loading
Loading
Loading
+7 −58
Original line number Diff line number Diff line
@@ -16,76 +16,25 @@

package com.android.systemui.keyguard.ui.composable.section

import android.view.View
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.onPlaced
import androidx.compose.ui.layout.positionInWindow
import androidx.compose.ui.viewinterop.AndroidView
import com.android.compose.animation.scene.ElementKey
import com.android.compose.animation.scene.SceneScope
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.keyguard.ui.viewmodel.KeyguardRootViewModel
import com.android.systemui.res.R
import com.android.systemui.scene.shared.flag.SceneContainerFlags
import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayoutController
import com.android.systemui.statusbar.notification.stack.NotificationStackSizeCalculator
import com.android.systemui.statusbar.notification.stack.ui.view.SharedNotificationContainer
import com.android.systemui.statusbar.notification.stack.ui.viewbinder.SharedNotificationContainerBinder
import com.android.systemui.statusbar.notification.stack.ui.viewmodel.SharedNotificationContainerViewModel
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
constructor(
    private val rootViewModel: KeyguardRootViewModel,
    private val sharedNotificationContainer: SharedNotificationContainer,
    private val sharedNotificationContainerViewModel: SharedNotificationContainerViewModel,
    private val controller: NotificationStackScrollLayoutController,
    private val notificationStackSizeCalculator: NotificationStackSizeCalculator,
    @Main private val dispatcher: CoroutineDispatcher,
    private val sceneContainerFlags: SceneContainerFlags,
    private val viewModel: NotificationsPlaceholderViewModel,
) {
    @Composable
    fun SceneScope.Notifications(modifier: Modifier = Modifier) {
        MovableElement(
            key = NotificationsElementKey,
        NotificationStack(
            viewModel = viewModel,
            isScrimVisible = false,
            modifier = modifier,
        ) {
            val (bounds, onBoundsChanged) = remember { mutableStateOf<Pair<Float, Float>?>(null) }
            LaunchedEffect(bounds) {
                bounds?.let {
                    rootViewModel.onNotificationContainerBoundsChanged(bounds.first, bounds.second)
                }
            }

            AndroidView(
                factory = { context ->
                    View(context, null).apply {
                        id = R.id.nssl_placeholder
                        SharedNotificationContainerBinder.bind(
                            view = sharedNotificationContainer,
                            viewModel = sharedNotificationContainerViewModel,
                            sceneContainerFlags = sceneContainerFlags,
                            controller = controller,
                            notificationStackSizeCalculator = notificationStackSizeCalculator,
                            mainImmediateDispatcher = dispatcher,
                        )
                    }
                },
                modifier =
                    modifier.onPlaced {
                        val positionInRoot = it.positionInWindow()
                        val size = it.size
                        onBoundsChanged(positionInRoot.y to positionInRoot.y + size.height)
                    },
        )
    }
}
}

private val NotificationsElementKey = ElementKey("Notifications")