[fenix] Prevent flash when navigating to home

pull/600/head
Christian Sadilek 3 years ago committed by mergify[bot]
parent 57f46aa08e
commit 9150d8061b

@ -320,6 +320,7 @@ abstract class BaseBrowserFragment :
engineView = binding.engineView, engineView = binding.engineView,
homeViewModel = homeViewModel, homeViewModel = homeViewModel,
customTabSessionId = customTabSessionId, customTabSessionId = customTabSessionId,
browserAnimator = browserAnimator,
onTabCounterClicked = { onTabCounterClicked = {
thumbnailsFeature.get()?.requestScreenshot() thumbnailsFeature.get()?.requestScreenshot()
findNavController().nav( findNavController().nav(

@ -42,8 +42,14 @@ class BrowserAnimator(
} }
/** /**
* Makes the swipeRefresh background a screenshot of the engineView in its current state. * Captures a screenshot of the current web page and sets the bitmap
* This allows us to "animate" the engineView. * as a background of the engine view's parent (the swipeRefresh view).
*
* This is a workaround to prevent the home screen from flashing behind
* the browser fragment when navigating away. We've also found this to
* make transitions from the browser fragment to the home fragment
* smoother. So, in addition, we are currently also using it as a
* workaround to prevent flashes during those navigations.
*/ */
fun captureEngineViewAndDrawStatically(onComplete: () -> Unit) { fun captureEngineViewAndDrawStatically(onComplete: () -> Unit) {
unwrappedEngineView?.asView()?.context.let { unwrappedEngineView?.asView()?.context.let {

@ -18,6 +18,7 @@ import mozilla.components.ui.tabcounter.TabCounterMenu
import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.browser.BrowserAnimator
import org.mozilla.fenix.browser.BrowserAnimator.Companion.getToolbarNavOptions import org.mozilla.fenix.browser.BrowserAnimator.Companion.getToolbarNavOptions
import org.mozilla.fenix.browser.BrowserFragmentDirections import org.mozilla.fenix.browser.BrowserFragmentDirections
import org.mozilla.fenix.browser.browsingmode.BrowsingMode import org.mozilla.fenix.browser.browsingmode.BrowsingMode
@ -58,6 +59,7 @@ class DefaultBrowserToolbarController(
private val engineView: EngineView, private val engineView: EngineView,
private val homeViewModel: HomeScreenViewModel, private val homeViewModel: HomeScreenViewModel,
private val customTabSessionId: String?, private val customTabSessionId: String?,
private val browserAnimator: BrowserAnimator,
private val onTabCounterClicked: () -> Unit, private val onTabCounterClicked: () -> Unit,
private val onCloseTab: (SessionState) -> Unit private val onCloseTab: (SessionState) -> Unit
) : BrowserToolbarController { ) : BrowserToolbarController {
@ -97,16 +99,25 @@ class DefaultBrowserToolbarController(
// If we don't, there's a visual flickr as we navigate to Home and then display search // If we don't, there's a visual flickr as we navigate to Home and then display search
// results on top it. // results on top it.
if (FeatureFlags.showHomeBehindSearch && currentSession?.content?.searchTerms.isNullOrBlank()) { if (FeatureFlags.showHomeBehindSearch && currentSession?.content?.searchTerms.isNullOrBlank()) {
browserAnimator.captureEngineViewAndDrawStatically {
navController.navigate(
BrowserFragmentDirections.actionGlobalHome()
)
navController.navigate(
BrowserFragmentDirections.actionGlobalSearchDialog(
currentSession?.id
),
getToolbarNavOptions(activity)
)
}
} else {
navController.navigate( navController.navigate(
BrowserFragmentDirections.actionGlobalHome() BrowserFragmentDirections.actionGlobalSearchDialog(
currentSession?.id
),
getToolbarNavOptions(activity)
) )
} }
navController.navigate(
BrowserFragmentDirections.actionGlobalSearchDialog(
currentSession?.id
),
getToolbarNavOptions(activity)
)
} }
override fun handleTabCounterClick() { override fun handleTabCounterClick() {
@ -163,9 +174,11 @@ class DefaultBrowserToolbarController(
override fun handleHomeButtonClick() { override fun handleHomeButtonClick() {
metrics.track(Event.BrowserToolbarHomeButtonClicked) metrics.track(Event.BrowserToolbarHomeButtonClicked)
navController.navigate( browserAnimator.captureEngineViewAndDrawStatically {
BrowserFragmentDirections.actionGlobalHome() navController.navigate(
) BrowserFragmentDirections.actionGlobalHome()
)
}
} }
companion object { companion object {

@ -356,6 +356,7 @@ class DefaultBrowserToolbarControllerTest {
homeViewModel = homeViewModel, homeViewModel = homeViewModel,
customTabSessionId = customTabSessionId, customTabSessionId = customTabSessionId,
readerModeController = readerModeController, readerModeController = readerModeController,
browserAnimator = browserAnimator,
onTabCounterClicked = { onTabCounterClicked = {
tabCounterClicked = true tabCounterClicked = true
}, },

Loading…
Cancel
Save