commit d9bfbc144e7941fc8564230d84118ae1e1caaa58 parent fe709b5b10a87327bfd0de8ec58661308bbb34e0 Author: Alex Jakobi <ajakobi@mozilla.com> Date: Wed, 15 Oct 2025 13:55:18 +0000 Bug 1917726 - Don't force-expand toolbars during gestures that resemble a scroll up gesture. r=mstange,android-reviewers,petru Differential Revision: https://phabricator.services.mozilla.com/D266354 Diffstat:
2 files changed, 6 insertions(+), 51 deletions(-)
diff --git a/mobile/android/android-components/components/ui/widgets/src/main/java/mozilla/components/ui/widgets/behavior/EngineViewScrollingBehavior.kt b/mobile/android/android-components/components/ui/widgets/src/main/java/mozilla/components/ui/widgets/behavior/EngineViewScrollingBehavior.kt @@ -96,7 +96,7 @@ class EngineViewScrollingBehavior( type: Int, ): Boolean { return if (dynamicScrollView != null) { - startNestedScroll(axes, type, child) + startNestedScroll(axes, type) } else { return false // not interested in subsequent scroll events } @@ -172,12 +172,6 @@ class EngineViewScrollingBehavior( dynamicScrollView?.let { view -> if (shouldScroll && startedScroll) { yTranslator.translate(view, distance) - } else if (engineView?.getInputResultDetail()?.isTouchHandlingUnknown() == false) { - // Force expand the view if the user scrolled up, it is not already expanded and - // an animation to expand it is not already in progress, - // otherwise the user could get stuck in a state where they cannot show the view - // See https://github.com/mozilla-mobile/android-components/issues/7101 - yTranslator.forceExpandIfNotAlready(view, distance) } } } @@ -210,18 +204,12 @@ class EngineViewScrollingBehavior( ) @VisibleForTesting - internal fun startNestedScroll(axes: Int, type: Int, view: View): Boolean { + internal fun startNestedScroll(axes: Int, type: Int): Boolean { return if (shouldScroll && axes == ViewCompat.SCROLL_AXIS_VERTICAL) { startedScroll = true shouldSnapAfterScroll = type == ViewCompat.TYPE_TOUCH yTranslator.cancelInProgressTranslation() true - } else if (engineView?.getInputResultDetail()?.isTouchUnhandled() == true) { - // Force expand the view if event is unhandled, otherwise user could get stuck in a - // state where they cannot show the view - yTranslator.cancelInProgressTranslation() - yTranslator.expandWithAnimation(view) - false } else { false } diff --git a/mobile/android/android-components/components/ui/widgets/src/test/java/mozilla/components/ui/widgets/behavior/EngineViewScrollingBehaviorTest.kt b/mobile/android/android-components/components/ui/widgets/src/test/java/mozilla/components/ui/widgets/behavior/EngineViewScrollingBehaviorTest.kt @@ -15,7 +15,6 @@ import androidx.core.view.ViewCompat import androidx.test.ext.junit.runners.AndroidJUnit4 import mozilla.components.concept.engine.EngineSession import mozilla.components.concept.engine.EngineView -import mozilla.components.concept.engine.INPUT_UNHANDLED import mozilla.components.concept.engine.InputResultDetail import mozilla.components.concept.engine.selection.SelectionActionDelegate import mozilla.components.support.test.any @@ -51,7 +50,7 @@ class EngineViewScrollingBehaviorTest { type = ViewCompat.TYPE_TOUCH, ) assertFalse(acceptsNestedScroll) - verify(behavior, never()).startNestedScroll(anyInt(), anyInt(), any()) + verify(behavior, never()).startNestedScroll(anyInt(), anyInt()) behavior.dynamicScrollView = mock() acceptsNestedScroll = behavior.onStartNestedScroll( @@ -63,7 +62,7 @@ class EngineViewScrollingBehaviorTest { type = ViewCompat.TYPE_TOUCH, ) assertTrue(acceptsNestedScroll) - verify(behavior).startNestedScroll(anyInt(), anyInt(), any()) + verify(behavior).startNestedScroll(anyInt(), anyInt()) } @Test @@ -76,7 +75,6 @@ class EngineViewScrollingBehaviorTest { val acceptsNestedScroll = behavior.startNestedScroll( axes = ViewCompat.SCROLL_AXIS_VERTICAL, type = ViewCompat.TYPE_TOUCH, - view = mock(), ) assertTrue(acceptsNestedScroll) @@ -91,20 +89,18 @@ class EngineViewScrollingBehaviorTest { var acceptsNestedScroll = behavior.startNestedScroll( axes = ViewCompat.SCROLL_AXIS_VERTICAL, type = ViewCompat.TYPE_TOUCH, - view = mock(), ) assertTrue(acceptsNestedScroll) acceptsNestedScroll = behavior.startNestedScroll( axes = ViewCompat.SCROLL_AXIS_HORIZONTAL, type = ViewCompat.TYPE_TOUCH, - view = mock(), ) assertFalse(acceptsNestedScroll) } @Test - fun `GIVEN a gesture that doesn't scroll the toolbar WHEN startNestedScroll THEN toolbar is expanded and nested scroll not accepted`() { + fun `GIVEN a gesture that doesn't scroll the toolbar WHEN startNestedScroll THEN nested scroll is not accepted`() { val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM)) val engineView: EngineView = mock() val inputResultDetail: InputResultDetail = mock() @@ -118,11 +114,8 @@ class EngineViewScrollingBehaviorTest { val acceptsNestedScroll = behavior.startNestedScroll( axes = ViewCompat.SCROLL_AXIS_VERTICAL, type = ViewCompat.TYPE_TOUCH, - view = mock(), ) - verify(yTranslator).cancelInProgressTranslation() - verify(yTranslator).expandWithAnimation(any()) assertFalse(acceptsNestedScroll) } @@ -170,7 +163,7 @@ class EngineViewScrollingBehaviorTest { type = inputType, ) - verify(behavior).startNestedScroll(axes, inputType, view) + verify(behavior).startNestedScroll(axes, inputType) } @Test @@ -473,32 +466,6 @@ class EngineViewScrollingBehaviorTest { } @Test - fun `Behavior will forceExpand when scrolling up and !shouldScroll if the touch was handled in the browser`() { - val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM)) - val yTranslator: ViewYTranslator = mock() - behavior.yTranslator = yTranslator - behavior.initGesturesDetector(behavior.createGestureDetector()) - val view: View = spy(View(testContext, null, 0)) - behavior.dynamicScrollView = view - val engineView: EngineView = mock() - behavior.engineView = engineView - val handledTouchInput = InputResultDetail.newInstance().copy(INPUT_UNHANDLED) - doReturn(handledTouchInput).`when`(engineView).getInputResultDetail() - - doReturn(100).`when`(view).height - doReturn(100f).`when`(view).translationY - - val downEvent = TestUtils.getMotionEvent(ACTION_DOWN, 0f, 0f) - val moveEvent = TestUtils.getMotionEvent(ACTION_MOVE, 0f, 30f, downEvent) - - behavior.onInterceptTouchEvent(mock(), mock(), downEvent) - behavior.onInterceptTouchEvent(mock(), mock(), moveEvent) - - verify(behavior).tryToScrollVertically(-30f) - verify(yTranslator).forceExpandIfNotAlready(view, -30f) - } - - @Test fun `Behavior will not forceExpand when scrolling up and !shouldScroll if the touch was not yet handled in the browser`() { val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM)) val yTranslator: ViewYTranslator = mock()