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

Commit 3e8e34f0 authored by Luna Zhang's avatar Luna Zhang Committed by Android (Google) Code Review
Browse files

Merge "Support notification center scroll via mousewheel" into main

parents 74fe960d 73249a83
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -23,11 +23,13 @@ import androidx.compose.foundation.layout.offset
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.unit.IntOffset
import com.android.compose.nestedscroll.PriorityNestedScrollConnection
import com.android.systemui.common.ui.compose.windowinsets.LocalRawScreenHeight
import kotlin.math.max
import kotlin.math.roundToInt
import kotlin.math.tanh
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

@@ -36,6 +38,7 @@ fun Modifier.stackVerticalOverscroll(
    coroutineScope: CoroutineScope,
    canScrollForward: () -> Boolean
): Modifier {
    val screenHeight = LocalRawScreenHeight.current
    val overscrollOffset = remember { Animatable(0f) }
    val stackNestedScrollConnection = remember {
        NotificationStackNestedScrollConnection(
@@ -43,7 +46,13 @@ fun Modifier.stackVerticalOverscroll(
            canScrollForward = canScrollForward,
            onScroll = { offsetAvailable ->
                coroutineScope.launch {
                    overscrollOffset.snapTo(overscrollOffset.value + offsetAvailable * 0.3f)
                    val maxProgress = screenHeight * 0.2f
                    val tilt = 3f
                    var offset =
                        overscrollOffset.value +
                            maxProgress * tanh(x = offsetAvailable / (maxProgress * tilt))
                    offset = max(offset, -1f * maxProgress)
                    overscrollOffset.snapTo(offset)
                }
            },
            onStop = { velocityAvailable ->
@@ -79,13 +88,7 @@ fun NotificationStackNestedScrollConnection(
            offsetAvailable < 0f && offsetBeforeStart < 0f && !canScrollForward()
        },
        canStartPostFling = { velocityAvailable -> velocityAvailable < 0f && !canScrollForward() },
        canContinueScroll = { source ->
            if (source == NestedScrollSource.SideEffect) {
                stackOffset() > STACK_OVERSCROLL_FLING_MIN_OFFSET
            } else {
                true
            }
        },
        canContinueScroll = { stackOffset() > 0f },
        canScrollOnFling = true,
        onStart = { offsetAvailable -> onStart(offsetAvailable) },
        onScroll = { offsetAvailable ->
+0 −1
Original line number Diff line number Diff line
@@ -667,4 +667,3 @@ private val DEBUG_HUN_COLOR = Color(0f, 0f, 1f, 0.2f)
private val DEBUG_BOX_COLOR = Color(0f, 1f, 0f, 0.2f)
private const val HUN_SNOOZE_POSITIONAL_THRESHOLD_FRACTION = 0.25f
private const val HUN_SNOOZE_VELOCITY_THRESHOLD = -70f
internal const val STACK_OVERSCROLL_FLING_MIN_OFFSET = -100f
+4 −0
Original line number Diff line number Diff line
@@ -3691,6 +3691,10 @@ public class NotificationStackScrollLayout
        if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_SCROLL: {
                    // If scene container is active, NSSL should not control its own scrolling.
                    if (SceneContainerFlag.isEnabled()) {
                        return false;
                    }
                    if (!mIsBeingDragged) {
                        final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                        if (vscroll != 0) {