From 790c291d0dd6f5cc018f7763930a3b0dd2510a79 Mon Sep 17 00:00:00 2001 From: Jeff Boek Date: Tue, 23 Jun 2020 08:50:20 -0700 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/11261 - Dismisses menu when rotating to landscape (https://github.com/mozilla-mobile/fenix/pull/11845) --- .../fenix/tabtray/TabTrayDialogFragment.kt | 1 + .../java/org/mozilla/fenix/tabtray/TabTrayView.kt | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayDialogFragment.kt b/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayDialogFragment.kt index 151756e32a..df9c9267a9 100644 --- a/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayDialogFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayDialogFragment.kt @@ -94,6 +94,7 @@ class TabTrayDialogFragment : AppCompatDialogFragment() { tabTrayView.setTopOffset(isLandscape) if (isLandscape) { + tabTrayView.dismissMenu() tabTrayView.expand() } } diff --git a/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayView.kt b/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayView.kt index eaec5b4552..5c5bc09c33 100644 --- a/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayView.kt +++ b/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayView.kt @@ -21,6 +21,7 @@ import kotlinx.android.synthetic.main.component_tabstray_fab.view.* import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.delay import kotlinx.coroutines.launch +import mozilla.components.browser.menu.BrowserMenu import mozilla.components.browser.menu.BrowserMenuBuilder import mozilla.components.browser.menu.item.SimpleBrowserMenuItem import mozilla.components.browser.state.selector.normalTabs @@ -54,7 +55,8 @@ class TabTrayView( private val behavior = BottomSheetBehavior.from(view.tab_wrapper) - private var tabTrayItemMenu: TabTrayItemMenu + private val tabTrayItemMenu: TabTrayItemMenu + private var menu: BrowserMenu? = null private var hasLoaded = false @@ -149,10 +151,9 @@ class TabTrayView( } view.tab_tray_overflow.setOnClickListener { - tabTrayItemMenu.menuBuilder - .build(view.context) - .show(anchor = it) - .also { pu -> + menu = tabTrayItemMenu.menuBuilder.build(container.context) + menu?.show(it) + ?.also { pu -> (pu.contentView as? CardView)?.setCardBackgroundColor(ContextCompat.getColor( view.context, R.color.foundation_normal_theme @@ -241,6 +242,10 @@ class TabTrayView( behavior.setExpandedOffset(topOffset) } + fun dismissMenu() { + menu?.dismiss() + } + companion object { private const val DEFAULT_TAB_ID = 0 private const val PRIVATE_TAB_ID = 1