For #1901: Screenshot engineView to remove GV flash
Co-authored-by: ekager <ekager@mozilla.com>master
parent
0630e2482f
commit
d918cfdf38
|
@ -15,6 +15,7 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import androidx.annotation.CallSuper
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.core.graphics.drawable.toDrawable
|
||||
import androidx.core.net.toUri
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
|
@ -475,9 +476,16 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
|
|||
|
||||
private fun adjustBackgroundAndNavigate(directions: NavDirections) {
|
||||
context?.let {
|
||||
swipeRefresh?.background = ColorDrawable(Color.TRANSPARENT)
|
||||
engineView?.asView()?.visibility = View.GONE
|
||||
findNavController().nav(R.id.browserFragment, directions)
|
||||
engineView.captureThumbnail { bitmap ->
|
||||
lifecycleScope.launch {
|
||||
// If the bitmap is null, the best we can do to reduce the flash is set transparent
|
||||
swipeRefresh.background = bitmap?.toDrawable(it.resources)
|
||||
?: ColorDrawable(Color.TRANSPARENT)
|
||||
|
||||
engineView.asView().visibility = View.GONE
|
||||
findNavController().nav(R.id.browserFragment, directions)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -531,9 +539,9 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
|
|||
@CallSuper
|
||||
override fun onBackPressed(): Boolean {
|
||||
return findInPageIntegration.onBackPressed() ||
|
||||
fullScreenFeature.onBackPressed() ||
|
||||
sessionFeature.onBackPressed() ||
|
||||
removeSessionIfNeeded()
|
||||
fullScreenFeature.onBackPressed() ||
|
||||
sessionFeature.onBackPressed() ||
|
||||
removeSessionIfNeeded()
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,6 +11,7 @@ import android.graphics.drawable.ColorDrawable
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.core.graphics.drawable.toDrawable
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.NavDirections
|
||||
import androidx.navigation.NavOptions
|
||||
|
@ -184,14 +185,18 @@ class DefaultBrowserToolbarController(
|
|||
val directions = BrowserFragmentDirections.actionBrowserFragmentToSearchFragment(
|
||||
sessionId = null
|
||||
)
|
||||
adjustBackgroundAndNavigate.invoke(directions)
|
||||
|
||||
// Do not adjustBackground here or an exception gets thrown as we switch themes
|
||||
navController.nav(R.id.browserFragment, directions)
|
||||
browsingModeManager.mode = BrowsingMode.Normal
|
||||
}
|
||||
ToolbarMenu.Item.NewPrivateTab -> {
|
||||
val directions = BrowserFragmentDirections.actionBrowserFragmentToSearchFragment(
|
||||
sessionId = null
|
||||
)
|
||||
adjustBackgroundAndNavigate.invoke(directions)
|
||||
|
||||
// Do not adjustBackground here or an exception gets thrown as we switch themes
|
||||
navController.nav(R.id.browserFragment, directions)
|
||||
browsingModeManager.mode = BrowsingMode.Private
|
||||
}
|
||||
ToolbarMenu.Item.FindInPage -> {
|
||||
|
@ -299,16 +304,22 @@ class DefaultBrowserToolbarController(
|
|||
browserLayout,
|
||||
"${TAB_ITEM_TRANSITION_NAME}${currentSession?.id}"
|
||||
).build()
|
||||
swipeRefresh.background = ColorDrawable(Color.TRANSPARENT)
|
||||
engineView.asView().visibility = View.GONE
|
||||
if (!navController.popBackStack(R.id.homeFragment, false)) {
|
||||
navController.nav(
|
||||
R.id.browserFragment,
|
||||
R.id.action_browserFragment_to_homeFragment,
|
||||
null,
|
||||
options,
|
||||
extras
|
||||
)
|
||||
engineView.captureThumbnail { bitmap ->
|
||||
scope.launch {
|
||||
// If the bitmap is null, the best we can do to reduce the flash is set transparent
|
||||
swipeRefresh.background = bitmap?.toDrawable(activity.resources)
|
||||
?: ColorDrawable(Color.TRANSPARENT)
|
||||
engineView.asView().visibility = View.GONE
|
||||
if (!navController.popBackStack(R.id.homeFragment, false)) {
|
||||
navController.nav(
|
||||
R.id.browserFragment,
|
||||
R.id.action_browserFragment_to_homeFragment,
|
||||
null,
|
||||
options,
|
||||
extras
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -367,7 +367,7 @@ class DefaultBrowserToolbarControllerTest {
|
|||
verify {
|
||||
val directions = BrowserFragmentDirections
|
||||
.actionBrowserFragmentToSearchFragment(sessionId = null)
|
||||
adjustBackgroundAndNavigate.invoke(directions)
|
||||
navController.nav(R.id.browserFragment, directions)
|
||||
}
|
||||
verify { browsingModeManager.mode = BrowsingMode.Private }
|
||||
}
|
||||
|
@ -438,7 +438,7 @@ class DefaultBrowserToolbarControllerTest {
|
|||
verify {
|
||||
val directions = BrowserFragmentDirections
|
||||
.actionBrowserFragmentToSearchFragment(sessionId = null)
|
||||
adjustBackgroundAndNavigate.invoke(directions)
|
||||
navController.nav(R.id.browserFragment, directions)
|
||||
}
|
||||
verify { browsingModeManager.mode = BrowsingMode.Normal }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue