1
0
Fork 0

For #10784 - Fixes memory leak in BrowserAnimator

master
ekager 2020-07-14 14:07:11 -04:00 committed by Emily Kager
parent f0c6bc0226
commit 1dc0ad39f4
2 changed files with 7 additions and 7 deletions

View File

@ -117,7 +117,7 @@ import java.lang.ref.WeakReference
@ExperimentalCoroutinesApi @ExperimentalCoroutinesApi
@Suppress("TooManyFunctions", "LargeClass") @Suppress("TooManyFunctions", "LargeClass")
abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, SessionManager.Observer { abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, SessionManager.Observer {
protected lateinit var browserFragmentStore: BrowserFragmentStore private lateinit var browserFragmentStore: BrowserFragmentStore
private lateinit var browserAnimator: BrowserAnimator private lateinit var browserAnimator: BrowserAnimator
private var _browserInteractor: BrowserToolbarViewInteractor? = null private var _browserInteractor: BrowserToolbarViewInteractor? = null
@ -195,7 +195,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
fragment = WeakReference(this), fragment = WeakReference(this),
engineView = WeakReference(engineView), engineView = WeakReference(engineView),
swipeRefresh = WeakReference(swipeRefresh), swipeRefresh = WeakReference(swipeRefresh),
viewLifecycleScope = viewLifecycleOwner.lifecycleScope, viewLifecycleScope = WeakReference(viewLifecycleOwner.lifecycleScope),
arguments = requireArguments() arguments = requireArguments()
).apply { ).apply {
beginAnimateInIfNecessary() beginAnimateInIfNecessary()
@ -514,7 +514,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
context.settings().setSitePermissionSettingListener(viewLifecycleOwner) { context.settings().setSitePermissionSettingListener(viewLifecycleOwner) {
// If the user connects to WIFI while on the BrowserFragment, this will update the // If the user connects to WIFI while on the BrowserFragment, this will update the
// SitePermissionsRules (specifically autoplay) accordingly // SitePermissionsRules (specifically autoplay) accordingly
this.context?.let { assignSitePermissionsRules(it) } assignSitePermissionsRules(context)
} }
assignSitePermissionsRules(context) assignSitePermissionsRules(context)

View File

@ -32,7 +32,7 @@ class BrowserAnimator(
private val fragment: WeakReference<Fragment>, private val fragment: WeakReference<Fragment>,
private val engineView: WeakReference<EngineView>, private val engineView: WeakReference<EngineView>,
private val swipeRefresh: WeakReference<View>, private val swipeRefresh: WeakReference<View>,
private val viewLifecycleScope: LifecycleCoroutineScope, private val viewLifecycleScope: WeakReference<LifecycleCoroutineScope>,
private val arguments: Bundle private val arguments: Bundle
) { ) {
@ -83,7 +83,7 @@ class BrowserAnimator(
fun beginAnimateInIfNecessary() { fun beginAnimateInIfNecessary() {
val shouldAnimate = arguments.getBoolean(SHOULD_ANIMATE_FLAG, false) val shouldAnimate = arguments.getBoolean(SHOULD_ANIMATE_FLAG, false)
if (shouldAnimate) { if (shouldAnimate) {
viewLifecycleScope.launch(Dispatchers.Main) { viewLifecycleScope.get()?.launch(Dispatchers.Main) {
delay(ANIMATION_DELAY) delay(ANIMATION_DELAY)
captureEngineViewAndDrawStatically { captureEngineViewAndDrawStatically {
unwrappedSwipeRefresh?.alpha = 0f unwrappedSwipeRefresh?.alpha = 0f
@ -101,7 +101,7 @@ class BrowserAnimator(
* Triggers the *zoom out* browser animation to run. * Triggers the *zoom out* browser animation to run.
*/ */
fun beginAnimateOut() { fun beginAnimateOut() {
viewLifecycleScope.launch(Dispatchers.Main) { viewLifecycleScope.get()?.launch(Dispatchers.Main) {
captureEngineViewAndDrawStatically { captureEngineViewAndDrawStatically {
unwrappedEngineView?.asView()?.visibility = View.GONE unwrappedEngineView?.asView()?.visibility = View.GONE
browserZoomInValueAnimator.reverse() browserZoomInValueAnimator.reverse()
@ -115,7 +115,7 @@ class BrowserAnimator(
*/ */
fun captureEngineViewAndDrawStatically(onComplete: () -> Unit) { fun captureEngineViewAndDrawStatically(onComplete: () -> Unit) {
unwrappedEngineView?.asView()?.context.let { unwrappedEngineView?.asView()?.context.let {
viewLifecycleScope.launch { viewLifecycleScope.get()?.launch {
// isAdded check is necessary because of a bug in viewLifecycleOwner. See AC#3828 // isAdded check is necessary because of a bug in viewLifecycleOwner. See AC#3828
if (!fragment.isAdded()) { if (!fragment.isAdded()) {
return@launch return@launch