Skip to content
This repository has been archived by the owner on Apr 17, 2021. It is now read-only.

Commit

Permalink
Issue #1865 - Move workaround to separate file.
Browse files Browse the repository at this point in the history
  • Loading branch information
liuche committed Mar 13, 2019
1 parent b838a60 commit b2c2998
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import kotlinx.android.synthetic.main.fragment_browser.view.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import mozilla.components.browser.session.Session
import mozilla.components.concept.engine.EngineView
import mozilla.components.concept.engine.permission.Permission
Expand Down Expand Up @@ -84,12 +80,7 @@ class WebRenderFragment : EngineViewLifecycleFragment(), Session.Observer {
override fun onResume() {
super.onResume()
if (session.isYoutubeTV) {
// Send key events on the UI thread to clear webview grey screen, see #1865
GlobalScope.launch(Dispatchers.Main) {
delay(50)
activity?.dispatchKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT))
activity?.dispatchKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_LEFT))
}
YoutubeGreyScreenWorkaround.invoke(activity)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.tv.firefox.webrender

import android.app.Activity
import android.view.KeyEvent
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

/**
* Workaround fix for intermittent grey screen that shows instead of WebView when returning to
* YouTube from the home screen, see #1865. Follow-up investigation in #1940.
*
* This fix sends navigation key events on the UI thread to dispel the grey screen.
*
* Other failed attempted workarounds:
* - Calling engineView.resume to trigger the webview to "load" from grey screen
* - Scrolling webview
* - Sending non-view-changing key events
*/
object YoutubeGreyScreenWorkaround {
fun invoke(activity: Activity?) {
GlobalScope.launch(Dispatchers.Main) {
delay(50)
activity?.dispatchKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT))
activity?.dispatchKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_LEFT))
}
}
}

0 comments on commit b2c2998

Please sign in to comment.