Skip to content

Commit

Permalink
For mozilla-mobile#6313 - On first load, hides engineView until first…
Browse files Browse the repository at this point in the history
…ContentfulPaint
  • Loading branch information
ekager committed May 14, 2020
1 parent cb30706 commit 190d024
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
engineView = WeakReference(engineView),
swipeRefresh = WeakReference(swipeRefresh),
viewLifecycleScope = viewLifecycleOwner.lifecycleScope,
arguments = requireArguments()
arguments = requireArguments(),
firstContentfulHappened = ::didFirstContentfulHappen
).apply {
beginAnimateInIfNecessary()
}
Expand Down Expand Up @@ -862,6 +863,15 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
}
}

private fun didFirstContentfulHappen(): Boolean {
val store = context?.components?.core?.store
val tabState = store?.state?.tabs?.find {
it.id == (customTabSessionId
?: context?.components?.core?.sessionManager?.selectedSession?.id)
}
return tabState?.content?.firstContentfulPaint == true
}

/*
* Dereference these views when the fragment view is destroyed to prevent memory leaks
*/
Expand Down
26 changes: 8 additions & 18 deletions app/src/main/java/org/mozilla/fenix/browser/BrowserAnimator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class BrowserAnimator(
private val engineView: WeakReference<EngineView>,
private val swipeRefresh: WeakReference<View>,
private val viewLifecycleScope: LifecycleCoroutineScope,
private val arguments: Bundle
private val arguments: Bundle,
private val firstContentfulHappened: () -> Boolean
) {

private val unwrappedEngineView: EngineView?
Expand All @@ -52,22 +53,9 @@ class BrowserAnimator(
}

doOnEnd {
unwrappedEngineView?.asView()?.visibility = View.VISIBLE
unwrappedSwipeRefresh?.background = null
arguments.putBoolean(SHOULD_ANIMATE_FLAG, false)
}

interpolator = DecelerateInterpolator()
duration = ANIMATION_DURATION
}

private val browserFadeInValueAnimator = ValueAnimator.ofFloat(0f, END_ANIMATOR_VALUE).apply {
addUpdateListener {
unwrappedSwipeRefresh?.alpha = it.animatedFraction
}

doOnEnd {
unwrappedEngineView?.asView()?.visibility = View.VISIBLE
if (firstContentfulHappened()) {
unwrappedEngineView?.asView()?.visibility = View.VISIBLE
}
unwrappedSwipeRefresh?.background = null
arguments.putBoolean(SHOULD_ANIMATE_FLAG, false)
}
Expand All @@ -92,7 +80,9 @@ class BrowserAnimator(
}
} else {
unwrappedSwipeRefresh?.alpha = 1f
unwrappedEngineView?.asView()?.visibility = View.VISIBLE
if (firstContentfulHappened()) {
unwrappedEngineView?.asView()?.visibility = View.VISIBLE
}
unwrappedSwipeRefresh?.background = null
}
}
Expand Down

0 comments on commit 190d024

Please sign in to comment.