Issue #18885: Dismiss FAB icon when tabs tray is closed

upstream-sync
Jonathan Almeida 3 years ago committed by Jonathan Almeida
parent ba218e638b
commit 1944a5ef6b

@ -34,7 +34,7 @@ class DefaultTabsTrayController(
private val browsingModeManager: BrowsingModeManager,
private val navController: NavController,
private val profiler: Profiler?,
private val dismissTabTray: () -> Unit,
private val navigationInteractor: NavigationInteractor,
private val metrics: MetricController,
private val ioScope: CoroutineScope,
private val accountManager: FxaAccountManager
@ -44,7 +44,7 @@ class DefaultTabsTrayController(
val startTime = profiler?.getProfilerTime()
browsingModeManager.mode = BrowsingMode.fromBoolean(isPrivate)
navController.navigate(TabTrayDialogFragmentDirections.actionGlobalHome(focusOnAddressBar = true))
dismissTabTray()
navigationInteractor.onTabTrayDismissed()
profiler?.addMarker(
"DefaultTabTrayController.onNewTabTapped",
startTime

@ -91,11 +91,22 @@ class TabsTrayFragment : AppCompatDialogFragment(), TabsTrayInteractor {
super.onViewCreated(view, savedInstanceState)
val activity = activity as HomeActivity
val navigationInteractor =
DefaultNavigationInteractor(
tabsTrayStore = tabsTrayStore,
browserStore = requireComponents.core.store,
navController = findNavController(),
metrics = requireComponents.analytics.metrics,
dismissTabTray = ::dismissAllowingStateLoss,
dismissTabTrayAndNavigateHome = ::dismissTabTrayAndNavigateHome,
bookmarksUseCase = requireComponents.useCases.bookmarksUseCases
)
tabsTrayController = DefaultTabsTrayController(
store = tabsTrayStore,
browsingModeManager = activity.browsingModeManager,
navController = findNavController(),
dismissTabTray = ::dismissAllowingStateLoss,
navigationInteractor = navigationInteractor,
profiler = requireComponents.core.engine.profiler,
accountManager = requireComponents.backgroundServices.accountManager,
metrics = requireComponents.analytics.metrics,
@ -111,17 +122,6 @@ class TabsTrayFragment : AppCompatDialogFragment(), TabsTrayInteractor {
requireComponents.analytics.metrics
)
val navigationInteractor =
DefaultNavigationInteractor(
tabsTrayStore = tabsTrayStore,
browserStore = requireComponents.core.store,
navController = findNavController(),
metrics = requireComponents.analytics.metrics,
dismissTabTray = ::dismissAllowingStateLoss,
dismissTabTrayAndNavigateHome = ::dismissTabTrayAndNavigateHome,
bookmarksUseCase = requireComponents.useCases.bookmarksUseCases
)
val syncedTabsTrayInteractor = SyncedTabsInteractor(
requireComponents.analytics.metrics,
requireActivity() as HomeActivity,
@ -138,6 +138,14 @@ class TabsTrayFragment : AppCompatDialogFragment(), TabsTrayInteractor {
syncedTabsTrayInteractor
)
behavior.addBottomSheetCallback(
TraySheetBehaviorCallback(
behavior,
navigationInteractor,
requireComponents.analytics.metrics
)
)
tabsTrayCtaBinding.set(
feature = TabsTrayInfoBannerBinding(
context = view.context,

@ -0,0 +1,32 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.tabstray
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_HIDDEN
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
class TraySheetBehaviorCallback(
private val behavior: BottomSheetBehavior<ConstraintLayout>,
private val trayInteractor: NavigationInteractor,
private val metrics: MetricController
) : BottomSheetBehavior.BottomSheetCallback() {
override fun onStateChanged(bottomSheet: View, newState: Int) {
if (newState == STATE_HIDDEN) {
metrics.track(Event.TabsTrayClosed)
trayInteractor.onTabTrayDismissed()
} else if (newState == BottomSheetBehavior.STATE_HALF_EXPANDED) {
// We only support expanded and collapsed states.
// But why??
behavior.state = STATE_HIDDEN
}
}
override fun onSlide(bottomSheet: View, slideOffset: Float) = Unit
}

@ -0,0 +1,63 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.tabstray
import androidx.constraintlayout.widget.ConstraintLayout
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_HALF_EXPANDED
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_HIDDEN
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_COLLAPSED
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_DRAGGING
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_SETTLING
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_EXPANDED
import io.mockk.Called
import io.mockk.mockk
import io.mockk.verify
import org.junit.Test
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
class TraySheetBehaviorCallbackTest {
@Test
fun `WHEN state is hidden THEN invoke interactor`() {
val interactor = mockk<NavigationInteractor>(relaxed = true)
val metrics = mockk<MetricController>(relaxed = true)
val callback = TraySheetBehaviorCallback(mockk(), interactor, metrics)
callback.onStateChanged(mockk(), STATE_HIDDEN)
verify { interactor.onTabTrayDismissed() }
verify { metrics.track(Event.TabsTrayClosed) }
}
@Test
fun `WHEN state is half-expanded THEN close the tray`() {
val behavior = mockk<BottomSheetBehavior<ConstraintLayout>>(relaxed = true)
val callback = TraySheetBehaviorCallback(behavior, mockk(), mockk())
callback.onStateChanged(mockk(), STATE_HALF_EXPANDED)
verify { behavior.state = STATE_HIDDEN }
}
@Test
fun `WHEN other states are invoked THEN do nothing`() {
val behavior = mockk<BottomSheetBehavior<ConstraintLayout>>(relaxed = true)
val interactor = mockk<NavigationInteractor>(relaxed = true)
val metrics = mockk<MetricController>(relaxed = true)
val callback = TraySheetBehaviorCallback(behavior, interactor, metrics)
callback.onStateChanged(mockk(), STATE_COLLAPSED)
callback.onStateChanged(mockk(), STATE_DRAGGING)
callback.onStateChanged(mockk(), STATE_SETTLING)
callback.onStateChanged(mockk(), STATE_EXPANDED)
verify { behavior wasNot Called }
verify { interactor wasNot Called }
verify { metrics wasNot Called }
}
}
Loading…
Cancel
Save