Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Fix "flashes" by using coverUntilFirstPaint() #8752

Closed
pocmo opened this issue Oct 20, 2020 · 3 comments
Closed

Fix "flashes" by using coverUntilFirstPaint() #8752

pocmo opened this issue Oct 20, 2020 · 3 comments
Labels
<engine-gecko> Component: browser-engine-gecko 🌟 feature New functionality and improvements

Comments

@pocmo
Copy link
Contributor

pocmo commented Oct 20, 2020

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

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

┆Issue is synchronized with this Jira Task

@pocmo pocmo added 🌟 feature New functionality and improvements <engine-gecko> Component: browser-engine-gecko labels Oct 20, 2020
@pocmo
Copy link
Contributor Author

pocmo commented Oct 20, 2020

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
Copy link
Contributor Author

pocmo commented Oct 20, 2020

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

@agi
Copy link
Contributor

agi commented Oct 20, 2020

Feel free to close #8747 as dupe since it's basically the same thing as this one.

ekager added a commit to ekager/android-components that referenced this issue Oct 26, 2020
ekager added a commit to ekager/android-components that referenced this issue Oct 26, 2020
ekager added a commit to ekager/android-components that referenced this issue Oct 27, 2020
ekager added a commit to ekager/android-components that referenced this issue Oct 28, 2020
ekager added a commit to ekager/android-components that referenced this issue Oct 29, 2020
@mergify mergify bot closed this as completed in 1d15599 Oct 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
<engine-gecko> Component: browser-engine-gecko 🌟 feature New functionality and improvements
Projects
None yet
Development

No branches or pull requests

2 participants