For #10433 - Pass in viewLifecycleScope to BrowserAnimator

fennec/production
ekager 4 years ago committed by Emily Kager
parent 9ec1f8e2d8
commit 9fd835de0f

@ -178,6 +178,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
fragment = WeakReference(this),
engineView = WeakReference(engineView),
swipeRefresh = WeakReference(swipeRefresh),
viewLifecycleScope = viewLifecycleOwner.lifecycleScope,
arguments = requireArguments()
).apply {
beginAnimateInIfNecessary()

@ -15,7 +15,6 @@ import androidx.core.animation.doOnEnd
import androidx.core.graphics.drawable.toDrawable
import androidx.fragment.app.Fragment
import androidx.lifecycle.LifecycleCoroutineScope
import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavOptions
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
@ -33,12 +32,10 @@ class BrowserAnimator(
private val fragment: WeakReference<Fragment>,
private val engineView: WeakReference<EngineView>,
private val swipeRefresh: WeakReference<View>,
private val viewLifecycleScope: LifecycleCoroutineScope,
private val arguments: Bundle
) {
private val viewLifeCycleScope: LifecycleCoroutineScope?
get() = fragment.get()?.viewLifecycleOwner?.lifecycleScope
private val unwrappedEngineView: EngineView?
get() = engineView.get()
@ -86,7 +83,7 @@ class BrowserAnimator(
fun beginAnimateInIfNecessary() {
val shouldAnimate = arguments.getBoolean(SHOULD_ANIMATE_FLAG, false)
if (shouldAnimate) {
viewLifeCycleScope?.launch(Dispatchers.Main) {
viewLifecycleScope.launch(Dispatchers.Main) {
delay(ANIMATION_DELAY)
captureEngineViewAndDrawStatically {
unwrappedSwipeRefresh?.alpha = 0f
@ -104,7 +101,7 @@ class BrowserAnimator(
* Triggers the *zoom out* browser animation to run.
*/
fun beginAnimateOut() {
viewLifeCycleScope?.launch(Dispatchers.Main) {
viewLifecycleScope.launch(Dispatchers.Main) {
captureEngineViewAndDrawStatically {
unwrappedEngineView?.asView()?.visibility = View.GONE
browserZoomInValueAnimator.reverse()
@ -118,11 +115,15 @@ class BrowserAnimator(
*/
fun captureEngineViewAndDrawStatically(onComplete: () -> Unit) {
unwrappedEngineView?.asView()?.context.let {
viewLifeCycleScope?.launch {
viewLifecycleScope.launch {
// isAdded check is necessary because of a bug in viewLifecycleOwner. See AC#3828
if (!fragment.isAdded()) { return@launch }
if (!fragment.isAdded()) {
return@launch
}
unwrappedEngineView?.captureThumbnail { bitmap ->
if (!fragment.isAdded()) { return@captureThumbnail }
if (!fragment.isAdded()) {
return@captureThumbnail
}
unwrappedSwipeRefresh?.apply {
// If the bitmap is null, the best we can do to reduce the flash is set transparent

Loading…
Cancel
Save