For #13405 - Use toolbar location relative to the whole screen instead of window.
parent
7f9ddfe051
commit
d9ffac0c89
|
@ -23,6 +23,7 @@ import mozilla.components.browser.session.Session
|
||||||
import mozilla.components.browser.session.SessionManager
|
import mozilla.components.browser.session.SessionManager
|
||||||
import mozilla.components.support.ktx.android.util.dpToPx
|
import mozilla.components.support.ktx.android.util.dpToPx
|
||||||
import mozilla.components.support.ktx.android.view.getRectWithViewLocation
|
import mozilla.components.support.ktx.android.view.getRectWithViewLocation
|
||||||
|
import org.mozilla.fenix.ext.getRectWithScreenLocation
|
||||||
import org.mozilla.fenix.ext.getWindowInsets
|
import org.mozilla.fenix.ext.getWindowInsets
|
||||||
import org.mozilla.fenix.ext.isKeyboardVisible
|
import org.mozilla.fenix.ext.isKeyboardVisible
|
||||||
import org.mozilla.fenix.ext.sessionsOfType
|
import org.mozilla.fenix.ext.sessionsOfType
|
||||||
|
@ -304,7 +305,7 @@ class ToolbarGestureHandler(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun PointF.isInToolbar(): Boolean {
|
private fun PointF.isInToolbar(): Boolean {
|
||||||
val toolbarLocation = toolbarLayout.getRectWithViewLocation()
|
val toolbarLocation = toolbarLayout.getRectWithScreenLocation()
|
||||||
// In Android 10, the system gesture touch area overlaps the bottom of the toolbar, so
|
// In Android 10, the system gesture touch area overlaps the bottom of the toolbar, so
|
||||||
// lets make our swipe area taller by that amount
|
// lets make our swipe area taller by that amount
|
||||||
activity.window.decorView.getWindowInsets()?.let { insets ->
|
activity.window.decorView.getWindowInsets()?.let { insets ->
|
||||||
|
|
|
@ -31,6 +31,20 @@ fun View.removeTouchDelegate() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fills a [Rect] with data about a view's location in the screen.
|
||||||
|
*
|
||||||
|
* @see View.getLocationOnScreen
|
||||||
|
* @see View.getRectWithViewLocation for a version of this that is relative to a window
|
||||||
|
*/
|
||||||
|
fun View.getRectWithScreenLocation(): Rect {
|
||||||
|
val locationOnScreen = IntArray(2).apply { getLocationOnScreen(this) }
|
||||||
|
return Rect(locationOnScreen[0],
|
||||||
|
locationOnScreen[1],
|
||||||
|
locationOnScreen[0] + width,
|
||||||
|
locationOnScreen[1] + height)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A safer version of [ViewCompat.getRootWindowInsets] that does not throw a NullPointerException
|
* A safer version of [ViewCompat.getRootWindowInsets] that does not throw a NullPointerException
|
||||||
* if the view is not attached.
|
* if the view is not attached.
|
||||||
|
|
|
@ -148,4 +148,22 @@ class ViewTest {
|
||||||
every { view.getKeyboardHeight() } returns 100
|
every { view.getKeyboardHeight() } returns 100
|
||||||
assertEquals(true, view.isKeyboardVisible())
|
assertEquals(true, view.isKeyboardVisible())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `getRectWithScreenLocation should transform getLocationInScreen method values`() {
|
||||||
|
val locationOnScreen = slot<IntArray>()
|
||||||
|
every { view.getLocationOnScreen(capture(locationOnScreen)) } answers {
|
||||||
|
locationOnScreen.captured[0] = 100
|
||||||
|
locationOnScreen.captured[1] = 200
|
||||||
|
}
|
||||||
|
every { view.width } returns 150
|
||||||
|
every { view.height } returns 250
|
||||||
|
|
||||||
|
val outRect = view.getRectWithScreenLocation()
|
||||||
|
|
||||||
|
assertEquals(100, outRect.left)
|
||||||
|
assertEquals(200, outRect.top)
|
||||||
|
assertEquals(250, outRect.right)
|
||||||
|
assertEquals(450, outRect.bottom)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue