From d66762910fd402b8456b3e74dade62a713bb1a66 Mon Sep 17 00:00:00 2001 From: ekager Date: Mon, 4 May 2020 23:29:33 -0700 Subject: [PATCH] For #6313 - On first load, hides engineView until firstContentfulPaint --- .../mozilla/fenix/ui/robots/BrowserRobot.kt | 7 +---- .../fenix/browser/BaseBrowserFragment.kt | 12 ++++++++- .../mozilla/fenix/browser/BrowserAnimator.kt | 26 ++++++------------- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BrowserRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BrowserRobot.kt index eb3fe0f0b..072201e50 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BrowserRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BrowserRobot.kt @@ -40,12 +40,6 @@ import org.mozilla.fenix.helpers.click import org.mozilla.fenix.helpers.ext.waitNotNull class BrowserRobot { - - fun verifyBrowserScreen() { - onView(ViewMatchers.withResourceName("browserLayout")) - .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) - } - fun verifyCurrentPrivateSession(context: Context) { val session = context.components.core.sessionManager.selectedSession assertTrue("Current session is private", session?.private!!) @@ -79,6 +73,7 @@ class BrowserRobot { */ fun verifyPageContent(expectedText: String) { val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) + mDevice.waitNotNull(Until.findObject(By.res("org.mozilla.fenix.debug:id/engineView")), waitingTime) mDevice.waitNotNull(Until.findObject(text(expectedText)), waitingTime) } diff --git a/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt index 8c5ac8dee..749f58df0 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt @@ -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() } @@ -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 */ diff --git a/app/src/main/java/org/mozilla/fenix/browser/BrowserAnimator.kt b/app/src/main/java/org/mozilla/fenix/browser/BrowserAnimator.kt index a4fd68e2b..ceb0f2720 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BrowserAnimator.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserAnimator.kt @@ -33,7 +33,8 @@ class BrowserAnimator( private val engineView: WeakReference, private val swipeRefresh: WeakReference, private val viewLifecycleScope: LifecycleCoroutineScope, - private val arguments: Bundle + private val arguments: Bundle, + private val firstContentfulHappened: () -> Boolean ) { private val unwrappedEngineView: EngineView? @@ -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) } @@ -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 } }