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

Commit d4ea4434 authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Android (Google) Code Review
Browse files

Merge "Surround ComposeView with FrameLayout for ignoring touches" into main

parents 2741910e cf947aa9
Loading
Loading
Loading
Loading
+89 −49
Original line number Original line Diff line number Diff line
@@ -17,12 +17,15 @@
package com.android.systemui.qs.composefragment
package com.android.systemui.qs.composefragment


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