For #19929: Use AC extension functions for window insets compat.

upstream-sync
mcarare 2 years ago committed by mergify[bot]
parent a4fa1f5a52
commit a9bb913653

@ -23,6 +23,8 @@ import mozilla.components.browser.state.state.TabSessionState
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.feature.tabs.TabsUseCases
import mozilla.components.support.ktx.android.view.getRectWithViewLocation
import mozilla.components.support.utils.ext.bottom
import mozilla.components.support.utils.ext.mandatorySystemGestureInsets
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.getRectWithScreenLocation
import org.mozilla.fenix.ext.getWindowInsets
@ -276,15 +278,13 @@ class ToolbarGestureHandler(
}.start()
}
@Suppress("DEPRECATION")
// https://github.com/mozilla-mobile/fenix/issues/19929
private fun PointF.isInToolbar(): Boolean {
val toolbarLocation = toolbarLayout.getRectWithScreenLocation()
// In Android 10, the system gesture touch area overlaps the bottom of the toolbar, so
// lets make our swipe area taller by that amount
activity.window.decorView.getWindowInsets()?.let { insets ->
if (activity.settings().shouldUseBottomToolbar) {
toolbarLocation.top -= (insets.mandatorySystemGestureInsets.bottom - insets.stableInsetBottom)
toolbarLocation.top -= (insets.mandatorySystemGestureInsets().bottom - insets.bottom())
}
}
return toolbarLocation.contains(toPoint())

@ -16,6 +16,7 @@ import androidx.annotation.Dimension.DP
import androidx.annotation.VisibleForTesting
import androidx.core.view.WindowInsetsCompat
import mozilla.components.support.ktx.android.util.dpToPx
import mozilla.components.support.utils.ext.bottom
import org.mozilla.fenix.R
fun View.increaseTapArea(@Dimension(unit = DP) extraDps: Int) {
@ -158,14 +159,12 @@ internal fun View.getWindowVisibleDisplayFrame(): Rect = with(Rect()) {
}
@VisibleForTesting
@Suppress("DEPRECATION")
// https://github.com/mozilla-mobile/fenix/issues/19929
internal fun View.getKeyboardHeight(): Int {
val windowRect = getWindowVisibleDisplayFrame()
val statusBarHeight = windowRect.top
var keyboardHeight = rootView.height - (windowRect.height() + statusBarHeight)
getWindowInsets()?.let {
keyboardHeight -= it.stableInsetBottom
keyboardHeight -= it.bottom()
}
return keyboardHeight

@ -22,6 +22,7 @@ import io.mockk.slot
import io.mockk.verify
import mozilla.components.support.ktx.android.util.dpToPx
import mozilla.components.support.test.robolectric.testContext
import mozilla.components.support.utils.ext.bottom
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
@ -41,6 +42,7 @@ class ViewTest {
fun setup() {
MockKAnnotations.init(this)
mockkStatic("mozilla.components.support.ktx.android.util.DisplayMetricsKt")
mockkStatic("mozilla.components.support.utils.ext.WindowInsetsCompatKt")
mockkStatic("org.mozilla.fenix.ext.ViewKt")
every { view.context } answers { testContext }
@ -112,14 +114,13 @@ class ViewTest {
}
@Test
@Suppress("DEPRECATION")
// https://github.com/mozilla-mobile/fenix/issues/19929
fun `getKeyboardHeight accounts for status bar and navigation bar`() {
val windowInsetsCompat: WindowInsetsCompat = mockk()
every { view.getWindowVisibleDisplayFrame() } returns Rect(0, 50, 1000, 500)
every { view.rootView.height } returns 1000
every { view.getWindowInsets() } returns mockk(relaxed = true) {
every { stableInsetBottom } returns 50
}
every { view.getWindowInsets() } returns windowInsetsCompat
every { windowInsetsCompat.bottom() } returns 50
assertEquals(450, view.getKeyboardHeight())
}

Loading…
Cancel
Save