Prevent flash when navigating to home

upstream-sync
Christian Sadilek 3 years ago committed by mergify[bot]
parent 28222df29c
commit ae0dba29b1

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

@ -42,8 +42,14 @@ class BrowserAnimator(
}
/**
* Makes the swipeRefresh background a screenshot of the engineView in its current state.
* This allows us to "animate" the engineView.
* Captures a screenshot of the current web page and sets the bitmap
* 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) {
unwrappedEngineView?.asView()?.context.let {

@ -18,6 +18,7 @@ import mozilla.components.ui.tabcounter.TabCounterMenu
import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.browser.BrowserAnimator
import org.mozilla.fenix.browser.BrowserAnimator.Companion.getToolbarNavOptions
import org.mozilla.fenix.browser.BrowserFragmentDirections
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
@ -58,6 +59,7 @@ class DefaultBrowserToolbarController(
private val engineView: EngineView,
private val homeViewModel: HomeScreenViewModel,
private val customTabSessionId: String?,
private val browserAnimator: BrowserAnimator,
private val onTabCounterClicked: () -> Unit,
private val onCloseTab: (SessionState) -> Unit
) : 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
// results on top it.
if (FeatureFlags.showHomeBehindSearch && currentSession?.content?.searchTerms.isNullOrBlank()) {
browserAnimator.captureEngineViewAndDrawStatically {
navController.navigate(
BrowserFragmentDirections.actionGlobalHome()
)
navController.navigate(
BrowserFragmentDirections.actionGlobalSearchDialog(
currentSession?.id
),
getToolbarNavOptions(activity)
)
}
} else {
navController.navigate(
BrowserFragmentDirections.actionGlobalHome()
BrowserFragmentDirections.actionGlobalSearchDialog(
currentSession?.id
),
getToolbarNavOptions(activity)
)
}
navController.navigate(
BrowserFragmentDirections.actionGlobalSearchDialog(
currentSession?.id
),
getToolbarNavOptions(activity)
)
}
override fun handleTabCounterClick() {
@ -163,9 +174,11 @@ class DefaultBrowserToolbarController(
override fun handleHomeButtonClick() {
metrics.track(Event.BrowserToolbarHomeButtonClicked)
navController.navigate(
BrowserFragmentDirections.actionGlobalHome()
)
browserAnimator.captureEngineViewAndDrawStatically {
navController.navigate(
BrowserFragmentDirections.actionGlobalHome()
)
}
}
companion object {

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

Loading…
Cancel
Save