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

Commit cf947aa9 authored by Fabián Kozynski's avatar Fabián Kozynski
Browse files

Surround ComposeView with FrameLayout for ignoring touches

This allows to ignore touches that are in the clipped area of QS. This
is the same treatment done in QSContainerImpl.

Test: manual, expand QS from anywhere in the shade
Bug: 353254353
Flag: com.android.systemui.qs_ui_refactor_compose_fragment

Change-Id: Ia1cc5678ea215adc6720f475e74dea3dae7a5785
parent 8e5da82a
Loading
Loading
Loading
Loading
+89 −49
Original line number Diff line number Diff line
@@ -17,12 +17,15 @@
package com.android.systemui.qs.composefragment

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.PointF
import android.graphics.Rect
import android.os.Bundle
import android.util.IndentingPrintWriter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.activity.OnBackPressedDispatcher
import androidx.activity.OnBackPressedDispatcherOwner
import androidx.activity.setViewTreeOnBackPressedDispatcherOwner
@@ -185,7 +188,8 @@ constructor(
        savedInstanceState: Bundle?,
    ): View {
        val context = inflater.context
        return ComposeView(context).apply {
        val composeView =
            ComposeView(context).apply {
                setBackPressedDispatcher()
                setContent {
                    PlatformTheme {
@@ -241,6 +245,19 @@ constructor(
                    }
                }
            }

        val frame =
            FrameLayoutTouchPassthrough(
                context,
                { notificationScrimClippingParams.isEnabled },
                { notificationScrimClippingParams.top },
            )
        frame.addView(
            composeView,
            FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT,
        )
        return frame
    }

    /**
@@ -762,3 +779,26 @@ private class ExpansionTransition(currentProgress: Float) :
}

private const val EDIT_MODE_TIME_MILLIS = 500

/**
 * Ignore touches below the value returned by [clippingTopProvider], when clipping is enabled, as
 * per [clippingEnabledProvider].
 */
private class FrameLayoutTouchPassthrough(
    context: Context,
    private val clippingEnabledProvider: () -> Boolean,
    private val clippingTopProvider: () -> Int,
) : FrameLayout(context) {
    override fun isTransformedTouchPointInView(
        x: Float,
        y: Float,
        child: View?,
        outLocalPoint: PointF?,
    ): Boolean {
        return if (clippingEnabledProvider() && y + translationY > clippingTopProvider()) {
            false
        } else {
            super.isTransformedTouchPointInView(x, y, child, outLocalPoint)
        }
    }
}