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

Commit a2481258 authored by András Kurucz's avatar András Kurucz
Browse files

[Flexiglass] Move top scrim padding from the NSSL to the NotificationPlaceholder

Bug: 332574413
Test: atest StackScrollAlgorithmTest
Flag: com.android.systemui.scene_container

Change-Id: Ia3f321df1b805676f4d2b84667bffb61116ada5c
parent d094bc7c
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -24,7 +24,9 @@ import androidx.compose.ui.node.LayoutModifierNode
import androidx.compose.ui.node.ModifierNodeElement
import androidx.compose.ui.node.invalidateMeasurement
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import com.android.systemui.statusbar.notification.stack.ui.view.NotificationScrollView

/**
@@ -32,14 +34,16 @@ import com.android.systemui.statusbar.notification.stack.ui.view.NotificationScr
 * by the legacy Notification stack scroll view in [NotificationScrollView.intrinsicStackHeight].
 *
 * @param view Notification stack scroll view
 * @param padding extra padding in pixels to be added to the received content height.
 * @param totalVerticalPadding extra padding to be added to the received stack content height.
 */
fun Modifier.notificationStackHeight(view: NotificationScrollView, padding: Int = 0) =
    this then StackLayoutElement(view, padding)
fun Modifier.notificationStackHeight(
    view: NotificationScrollView,
    totalVerticalPadding: Dp = 0.dp,
) = this then StackLayoutElement(view, totalVerticalPadding)

private data class StackLayoutElement(
    val view: NotificationScrollView,
    val padding: Int,
    val padding: Dp,
) : ModifierNodeElement<StackLayoutNode>() {

    override fun create(): StackLayoutNode = StackLayoutNode(view, padding)
@@ -53,7 +57,7 @@ private data class StackLayoutElement(
    }
}

private class StackLayoutNode(val view: NotificationScrollView, var padding: Int) :
private class StackLayoutNode(val view: NotificationScrollView, var padding: Dp) :
    LayoutModifierNode, Modifier.Node() {

    private val stackHeightChangedListener = Runnable { invalidateMeasureIfAttached() }
@@ -72,7 +76,7 @@ private class StackLayoutNode(val view: NotificationScrollView, var padding: Int
        measurable: Measurable,
        constraints: Constraints
    ): MeasureResult {
        val contentHeight = padding + view.intrinsicStackHeight
        val contentHeight = padding.roundToPx() + view.intrinsicStackHeight
        val placeable =
            measurable.measure(
                constraints.copy(minHeight = contentHeight, maxHeight = contentHeight)
+8 −6
Original line number Diff line number Diff line
@@ -196,11 +196,9 @@ fun SceneScope.NotificationScrollingStack(
        viewModel.isCurrentGestureOverscroll.collectAsStateWithLifecycle(false)
    val expansionFraction by viewModel.expandFraction.collectAsStateWithLifecycle(0f)

    val navBarHeightPx =
        with(density) {
            WindowInsets.systemBars.asPaddingValues().calculateBottomPadding().toPx().toInt()
        }
    val bottomPaddingPx = if (shouldReserveSpaceForNavBar) navBarHeightPx else 0
    val topPadding = dimensionResource(id = R.dimen.notification_side_paddings)
    val navBarHeight = WindowInsets.systemBars.asPaddingValues().calculateBottomPadding()
    val bottomPadding = if (shouldReserveSpaceForNavBar) navBarHeight else 0.dp

    val screenHeight = LocalRawScreenHeight.current

@@ -369,8 +367,12 @@ fun SceneScope.NotificationScrollingStack(
                            Modifier.nestedScroll(scrimNestedScrollConnection)
                        }
                        .verticalScroll(scrollState)
                        .padding(top = topPadding)
                        .fillMaxWidth()
                        .notificationStackHeight(view = stackScrollView, padding = bottomPaddingPx)
                        .notificationStackHeight(
                            view = stackScrollView,
                            totalVerticalPadding = topPadding + bottomPadding,
                        )
                        .onSizeChanged { size -> stackHeight.intValue = size.height },
            )
        }
+16 −4
Original line number Diff line number Diff line
@@ -2443,8 +2443,9 @@ public class NotificationStackScrollLayout
        return count;
    }

    private void updateContentHeight() {
        final float scrimTopPadding = mAmbientState.isOnKeyguard() ? 0 : mMinimumPaddings;
    @VisibleForTesting
    void updateContentHeight() {
        final float scrimTopPadding = getScrimTopPaddingOrZero();
        final int shelfIntrinsicHeight = mShelf != null ? mShelf.getIntrinsicHeight() : 0;
        final int footerIntrinsicHeight = mFooterView != null ? mFooterView.getIntrinsicHeight() : 0;
        final float height =
@@ -2949,7 +2950,7 @@ public class NotificationStackScrollLayout
        return view.getHeight();
    }

    public int getPositionInLinearLayout(View requestedView) {
    private int getPositionInLinearLayout(View requestedView) {
        ExpandableNotificationRow childInGroup = null;
        ExpandableNotificationRow requestedRow = null;
        if (isChildInGroup(requestedView)) {
@@ -2958,7 +2959,7 @@ public class NotificationStackScrollLayout
            childInGroup = (ExpandableNotificationRow) requestedView;
            requestedView = requestedRow = childInGroup.getNotificationParent();
        }
        final float scrimTopPadding = mAmbientState.isOnKeyguard() ? 0 : mMinimumPaddings;
        final float scrimTopPadding = getScrimTopPaddingOrZero();
        int position = (int) scrimTopPadding;
        int visibleIndex = -1;
        ExpandableView lastVisibleChild = null;
@@ -2988,6 +2989,17 @@ public class NotificationStackScrollLayout
        return 0;
    }

    /**
     * Returns the top scrim padding, or zero if the SceneContainer flag is enabled.
     */
    private int getScrimTopPaddingOrZero() {
        if (SceneContainerFlag.isEnabled()) {
            // the scrim padding is set on the notification placeholder
            return 0;
        }
        return mAmbientState.isOnKeyguard() ? 0 : mMinimumPaddings;
    }

    @Override
    public void onViewAdded(View child) {
        super.onViewAdded(child);
+0 −4
Original line number Diff line number Diff line
@@ -1609,10 +1609,6 @@ public class NotificationStackScrollLayoutController implements Dumpable {
        return mView.getTransientView(i);
    }

    public int getPositionInLinearLayout(ExpandableView row) {
        return mView.getPositionInLinearLayout(row);
    }

    public NotificationStackScrollLayout getView() {
        return mView;
    }
+23 −13
Original line number Diff line number Diff line
@@ -487,11 +487,8 @@ public class StackScrollAlgorithm {
        // expanded. Consider updating these states in updateContentView instead so that we don't
        // have to recalculate in every frame.
        float currentY = -ambientState.getScrollY();
        if (!ambientState.isOnKeyguard()
                || (ambientState.isBypassEnabled() && ambientState.isPulseExpanding())) {
        // add top padding at the start as long as we're not on the lock screen
            currentY += mNotificationScrimPadding;
        }
        currentY += getScrimTopPaddingOrZero(ambientState);
        state.firstViewInShelf = null;
        for (int i = 0; i < state.visibleChildren.size(); i++) {
            final ExpandableView view = state.visibleChildren.get(i);
@@ -548,11 +545,9 @@ public class StackScrollAlgorithm {
     */
    protected void updatePositionsForState(StackScrollAlgorithmState algorithmState,
            AmbientState ambientState) {
        if (!ambientState.isOnKeyguard()
                || (ambientState.isBypassEnabled() && ambientState.isPulseExpanding())) {
            algorithmState.mCurrentYPosition += mNotificationScrimPadding;
            algorithmState.mCurrentExpandedYPosition += mNotificationScrimPadding;
        }
        float scrimTopPadding = getScrimTopPaddingOrZero(ambientState);
        algorithmState.mCurrentYPosition += scrimTopPadding;
        algorithmState.mCurrentExpandedYPosition += scrimTopPadding;

        int childCount = algorithmState.visibleChildren.size();
        for (int i = 0; i < childCount; i++) {
@@ -580,9 +575,7 @@ public class StackScrollAlgorithm {
                && algorithmState.firstViewInShelf != null;

        final float shelfHeight = showingShelf ? ambientState.getShelf().getIntrinsicHeight() : 0f;
        final float scrimPadding = ambientState.isOnKeyguard()
                && (!ambientState.isBypassEnabled() || !ambientState.isPulseExpanding())
                ? 0 : mNotificationScrimPadding;
        final float scrimPadding = getScrimTopPaddingOrZero(ambientState);

        final float stackHeight = ambientState.getStackHeight() - shelfHeight - scrimPadding;
        final float stackEndHeight = ambientState.getStackEndHeight() - shelfHeight - scrimPadding;
@@ -594,6 +587,21 @@ public class StackScrollAlgorithm {
        return stackHeight / stackEndHeight;
    }

    /**
     * Returns the top scrim padding, or zero if the SceneContainer flag is enabled.
     */
    private float getScrimTopPaddingOrZero(AmbientState ambientState) {
        if (SceneContainerFlag.isEnabled()) {
            // the scrim padding is set on the notification placeholder
            return 0f;
        }

        boolean shouldUsePadding =
                !ambientState.isOnKeyguard()
                        || (ambientState.isBypassEnabled() && ambientState.isPulseExpanding());
        return shouldUsePadding ? mNotificationScrimPadding : 0f;
    }

    private boolean hasNonClearableNotifs(StackScrollAlgorithmState algorithmState) {
        for (int i = 0; i < algorithmState.visibleChildren.size(); i++) {
            View child = algorithmState.visibleChildren.get(i);
@@ -664,6 +672,7 @@ public class StackScrollAlgorithm {
        float viewEnd = stackTop + viewState.getYTranslation() + viewState.height;
        maybeUpdateHeadsUpIsVisible(viewState, ambientState.isShadeExpanded(),
                view.mustStayOnScreen(),
                // TODO(b/332574413) use the position from the HeadsUpNotificationPlaceholder
                /* topVisible= */ viewState.getYTranslation() >= mNotificationScrimPadding,
                viewEnd, /* hunMax */ ambientState.getMaxHeadsUpTranslation()
        );
@@ -891,6 +900,7 @@ public class StackScrollAlgorithm {
                    // Ensure that the heads up is always visible even when scrolled off.
                    // NSSL y starts at top of screen in non-split-shade, but below the qs offset
                    // in split shade, so we only need to inset by the scrim padding in split shade.
                    // TODO(b/332574413) get the clamp inset from HeadsUpNotificationPlaceholder
                    final float clampInset = ambientState.getUseSplitShade()
                            ? mNotificationScrimPadding : mQuickQsOffsetHeight;
                    clampHunToTop(clampInset, ambientState.getStackTranslation(),
Loading