For #17092: Dismiss toolbar menu when configuration change occurs (#17682)

upstream-sync
Roger Yang 3 years ago committed by GitHub
parent 66b94ced14
commit d434ff13a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,6 +6,7 @@ package org.mozilla.fenix.browser
import android.content.Context
import android.content.Intent
import android.content.res.Configuration
import android.os.Build
import android.os.Bundle
import android.view.Gravity
@ -1317,6 +1318,12 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler,
}
}
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
_browserToolbarView?.dismissMenu()
}
// This method is called in response to native web extension messages from
// content scripts (e.g the reader view extension). By the time these
// messages are processed the fragment/view may no longer be attached.

@ -235,6 +235,10 @@ class BrowserToolbarView(
}
}
fun dismissMenu() {
view.dismissMenu()
}
/**
* Dynamically sets scroll flags for the toolbar when the user does not have a screen reader enabled
* Note that the toolbar will have the flags set and be able to be hidden

@ -7,6 +7,7 @@ package org.mozilla.fenix.home
import android.animation.Animator
import android.content.Context
import android.content.DialogInterface
import android.content.res.Configuration
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
@ -168,6 +169,9 @@ class HomeFragment : Fragment() {
private val topSitesFeature = ViewBoundFeatureWrapper<TopSitesFeature>()
@VisibleForTesting
internal var getMenuButton: () -> MenuButton? = { menuButton }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -274,6 +278,12 @@ class HomeFragment : Fragment() {
return view
}
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
getMenuButton()?.dismissMenu()
}
private fun dismissTip(tip: Tip) {
sessionControlInteractor.onCloseTip(tip)
}

@ -346,6 +346,17 @@ class BrowserFragmentTest {
verify(exactly = 1) { toolbarIntegration.invalidateMenu() }
}
@Test
fun `WHEN fragment configuration changed THEN menu is dismissed`() {
val browserToolbarView: BrowserToolbarView = mockk(relaxed = true)
every { browserFragment.context } returns null
browserFragment._browserToolbarView = browserToolbarView
browserFragment.onConfigurationChanged(mockk(relaxed = true))
verify(exactly = 1) { browserToolbarView.dismissMenu() }
}
private fun addAndSelectTab(tab: TabSessionState) {
store.dispatch(TabListAction.AddTabAction(tab)).joinBlocking()
store.dispatch(TabListAction.SelectTabAction(tab.id)).joinBlocking()

@ -8,7 +8,9 @@ import android.content.Context
import io.mockk.every
import io.mockk.mockk
import io.mockk.spyk
import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi
import mozilla.components.browser.menu.view.MenuButton
import org.junit.Assert
import org.junit.Before
import org.junit.Test
@ -65,4 +67,13 @@ class HomeFragmentTest {
Assert.assertEquals(topSitesMaxLimit, topSitesConfig.totalSites)
}
@Test
fun `WHEN configuration changed menu is dismissed`() {
val menuButton: MenuButton = mockk(relaxed = true)
homeFragment.getMenuButton = { menuButton }
homeFragment.onConfigurationChanged(mockk(relaxed = true))
verify(exactly = 1) { menuButton.dismissMenu() }
}
}

Loading…
Cancel
Save