android-components icon indicating copy to clipboard operation
android-components copied to clipboard

Fix "flashes" by using coverUntilFirstPaint()

Open pocmo opened this issue 6 years ago • 3 comments

GeckoView: https://bugzilla.mozilla.org/show_bug.cgi?id=1665068

Example: https://paste.mozilla.org/hOTy9OsU

┆Issue is synchronized with this Jira Task

pocmo avatar Oct 20 '20 15:10 pocmo

Since the paste link may expire, this is the code:

    diff --git a/components/browser/engine-gecko-nightly/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngine.kt b/components/browser/engine-gecko-nightly/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngine.kt
    index 61e683fb5..d3fe115b5 100644
    --- a/components/browser/engine-gecko-nightly/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngine.kt
    +++ b/components/browser/engine-gecko-nightly/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngine.kt
    @@ -143,7 +143,7 @@ class GeckoEngine(
          * Creates a new Gecko-based EngineView.
          */
         override fun createView(context: Context, attrs: AttributeSet?): EngineView {
    -        return GeckoEngineView(context, attrs)
    +        return GeckoEngineView(context, attrs, preferredColorScheme=settings.preferredColorScheme)
         }
     
         /**
    diff --git a/components/browser/engine-gecko-nightly/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngineView.kt b/components/browser/engine-gecko-nightly/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngineView.kt
    index e1857f827..50e4d2ac9 100644
    --- a/components/browser/engine-gecko-nightly/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngineView.kt
    +++ b/components/browser/engine-gecko-nightly/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngineView.kt
    @@ -5,7 +5,9 @@
     package mozilla.components.browser.engine.gecko
     
     import android.content.Context
    +import android.content.res.Configuration
     import android.graphics.Bitmap
    +import android.graphics.Color
     import android.util.AttributeSet
     import android.widget.FrameLayout
     import androidx.annotation.VisibleForTesting
    @@ -13,6 +15,7 @@ import androidx.core.view.ViewCompat
     import mozilla.components.browser.engine.gecko.selection.GeckoSelectionActionDelegate
     import mozilla.components.concept.engine.EngineSession
     import mozilla.components.concept.engine.EngineView
    +import mozilla.components.concept.engine.mediaquery.PreferredColorScheme
     import mozilla.components.concept.engine.selection.SelectionActionDelegate
     import org.mozilla.geckoview.BasicSelectionActionDelegate
     import org.mozilla.geckoview.GeckoResult
    @@ -25,8 +28,10 @@ import org.mozilla.geckoview.GeckoSession
     class GeckoEngineView @JvmOverloads constructor(
         context: Context,
         attrs: AttributeSet? = null,
    -    defStyleAttr: Int = 0
    +    defStyleAttr: Int = 0,
    +    preferredColorScheme: PreferredColorScheme? = null
     ) : FrameLayout(context, attrs, defStyleAttr), EngineView {
    +
         @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
         internal var geckoView = object : NestedGeckoView(context) {
     
    @@ -59,6 +64,22 @@ class GeckoEngineView @JvmOverloads constructor(
             // autofill behavior for us here.
             @Suppress("WrongConstant")
             ViewCompat.setImportantForAutofill(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES)
    +
    +        var colorScheme = preferredColorScheme
    +        if (preferredColorScheme == PreferredColorScheme.System) {
    +            colorScheme = if (context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
    +                    == Configuration.UI_MODE_NIGHT_YES) {
    +                PreferredColorScheme.Dark
    +            } else {
    +                PreferredColorScheme.Light
    +            }
    +        }
    +
    +        if (colorScheme == PreferredColorScheme.Dark) {
    +            coverUntilFirstPaint(0xFF2A2A2E.toInt())
    +        } else {
    +            coverUntilFirstPaint(Color.WHITE)
    +        }
         }
     
         @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)

pocmo avatar Oct 20 '20 15:10 pocmo

With that we should be able to get rid of the code that shows/hides GeckoView based on the contentful paint event.

pocmo avatar Oct 20 '20 15:10 pocmo

Feel free to close https://github.com/mozilla-mobile/android-components/issues/8747 as dupe since it's basically the same thing as this one.

agi avatar Oct 20 '20 15:10 agi