From 6e0a64897b0cab11ec2808d218dbf35ddaea5174 Mon Sep 17 00:00:00 2001 From: Mugurell Date: Mon, 8 Feb 2021 19:34:12 +0200 Subject: [PATCH] For #17899 - Expand toolbar when returning from fullscreen video This was the previous behavior for both the top and bottom toolbars. Regressed when changing to use a new custom behavior for the top toolbar. When entering fullscreen we will now collapse and hide the toolbar, allow the browser to expand to the entire screen estate and then, when exiting fullscreen expand the toolbar. Collapsing and then expanding the toolbar will trigger the EngineViewBrowserToolbarBehavior to place the browser below the toolbar. --- .../fenix/browser/BaseBrowserFragment.kt | 3 +- .../components/toolbar/BrowserToolbarView.kt | 11 +++++ .../toolbar/BrowserToolbarViewTest.kt | 47 +++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt index 19644bf42..3718b2dfe 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt @@ -1220,6 +1220,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit .setText(getString(R.string.full_screen_notification)) .show() activity?.enterToImmersiveMode() + browserToolbarView.collapse() browserToolbarView.view.isVisible = false val browserEngine = swipeRefresh.layoutParams as CoordinatorLayout.LayoutParams browserEngine.bottomMargin = 0 @@ -1227,7 +1228,6 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit swipeRefresh.translationY = 0f engineView.setDynamicToolbarMaxHeight(0) - browserToolbarView.expand() // Without this, fullscreen has a margin at the top. engineView.setVerticalClipping(0) @@ -1241,6 +1241,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit browserToolbarView.view.isVisible = true val toolbarHeight = resources.getDimensionPixelSize(R.dimen.browser_toolbar_height) initializeEngineView(toolbarHeight) + browserToolbarView.expand() } } diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarView.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarView.kt index d8e7e306f..1b25af105 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarView.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarView.kt @@ -215,6 +215,17 @@ class BrowserToolbarView( } } + fun collapse() { + // collapse only for normal tabs and custom tabs not for PWA or TWA. Mirror expand() + if (isPwaTabOrTwaTab) { + return + } + + (view.layoutParams as? CoordinatorLayout.LayoutParams)?.apply { + (behavior as? BrowserToolbarBehavior)?.forceCollapse(view) + } + } + fun dismissMenu() { view.dismissMenu() } diff --git a/app/src/test/java/org/mozilla/fenix/components/toolbar/BrowserToolbarViewTest.kt b/app/src/test/java/org/mozilla/fenix/components/toolbar/BrowserToolbarViewTest.kt index f75b1d448..df34475e5 100644 --- a/app/src/test/java/org/mozilla/fenix/components/toolbar/BrowserToolbarViewTest.kt +++ b/app/src/test/java/org/mozilla/fenix/components/toolbar/BrowserToolbarViewTest.kt @@ -5,6 +5,7 @@ package org.mozilla.fenix.components.toolbar import androidx.coordinatorlayout.widget.CoordinatorLayout +import io.mockk.confirmVerified import io.mockk.every import io.mockk.mockk @@ -193,4 +194,50 @@ class BrowserToolbarViewTest { assertNotNull((toolbar.layoutParams as CoordinatorLayout.LayoutParams).behavior) } + + @Test + fun `expand should not do anything if isPwaTabOrTwaTab`() { + val toolbarViewSpy = spyk(toolbarView) + every { toolbarViewSpy.isPwaTabOrTwaTab } returns true + + toolbarViewSpy.expand() + + verify { toolbarViewSpy.expand() } + verify { toolbarViewSpy.isPwaTabOrTwaTab } + // verify that no other interactions than the expected ones took place + confirmVerified(toolbarViewSpy) + } + + @Test + fun `expand should call forceExpand if not isPwaTabOrTwaTab`() { + val toolbarViewSpy = spyk(toolbarView) + every { toolbarViewSpy.isPwaTabOrTwaTab } returns false + + toolbarViewSpy.expand() + + verify { behavior.forceExpand(toolbar) } + } + + @Test + fun `collapse should not do anything if isPwaTabOrTwaTab`() { + val toolbarViewSpy = spyk(toolbarView) + every { toolbarViewSpy.isPwaTabOrTwaTab } returns true + + toolbarViewSpy.collapse() + + verify { toolbarViewSpy.collapse() } + verify { toolbarViewSpy.isPwaTabOrTwaTab } + // verify that no other interactions than the expected ones took place + confirmVerified(toolbarViewSpy) + } + + @Test + fun `collapse should call forceExpand if not isPwaTabOrTwaTab`() { + val toolbarViewSpy = spyk(toolbarView) + every { toolbarViewSpy.isPwaTabOrTwaTab } returns false + + toolbarViewSpy.collapse() + + verify { behavior.forceCollapse(toolbar) } + } }