From b0f7acdaff9a8a5368b0ce5f2e4ade856b26c87a Mon Sep 17 00:00:00 2001 From: Christian Sadilek Date: Thu, 14 Jan 2021 11:59:37 -0500 Subject: [PATCH] [fenix] Closes https://github.com/mozilla-mobile/fenix/issues/17443: IllegalStateException in startPostponedEnterTransition on HomeFragment --- .../mozilla/fenix/browser/BrowserFragment.kt | 13 -------- .../org/mozilla/fenix/home/HomeFragment.kt | 16 --------- .../mozilla/fenix/home/HomeScreenViewModel.kt | 3 -- .../fenix/utils/FragmentPreDrawManager.kt | 30 ----------------- .../fenix/utils/FragmentPreDrawManagerTest.kt | 33 ------------------- 5 files changed, 95 deletions(-) delete mode 100644 app/src/main/java/org/mozilla/fenix/utils/FragmentPreDrawManager.kt delete mode 100644 app/src/test/java/org/mozilla/fenix/utils/FragmentPreDrawManagerTest.kt diff --git a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt index bf8bd8fc28..ec7db68bc6 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt @@ -5,9 +5,7 @@ package org.mozilla.fenix.browser import android.content.Context -import android.os.Bundle import android.os.StrictMode -import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.appcompat.content.res.AppCompatResources @@ -57,17 +55,6 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler { private var readerModeAvailable = false private var pwaOnboardingObserver: PwaOnboardingObserver? = null - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View { - val view = super.onCreateView(inflater, container, savedInstanceState) - - startPostponedEnterTransition() - return view - } - @Suppress("LongMethod") override fun initializeUI(view: View): Session? { val context = requireContext() diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt index 886088eccf..1642e2adf0 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt @@ -114,7 +114,6 @@ import org.mozilla.fenix.settings.SupportUtils import org.mozilla.fenix.settings.SupportUtils.SumoTopic.HELP import org.mozilla.fenix.settings.deletebrowsingdata.deleteAndQuit import org.mozilla.fenix.theme.ThemeManager -import org.mozilla.fenix.utils.FragmentPreDrawManager import org.mozilla.fenix.utils.ToolbarPopupWindow import org.mozilla.fenix.utils.allowUndo import org.mozilla.fenix.whatsnew.WhatsNew @@ -171,7 +170,6 @@ class HomeFragment : Fragment() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - postponeEnterTransition() bundleArgs = args.toBundle() lifecycleScope.launch(IO) { if (!onboarding.userHasBeenOnboarded()) { @@ -341,15 +339,7 @@ class HomeFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - FragmentPreDrawManager(this).execute { - homeViewModel.layoutManagerState?.also { parcelable -> - sessionControlView!!.view.layoutManager?.onRestoreInstanceState(parcelable) - } - homeViewModel.layoutManagerState = null - } - observeSearchEngineChanges() - createHomeMenu(requireContext(), WeakReference(view.menuButton)) createTabCounterMenu(view) @@ -654,12 +644,6 @@ class HomeFragment : Fragment() { }.show() } - override fun onStop() { - super.onStop() - homeViewModel.layoutManagerState = - sessionControlView!!.view.layoutManager?.onSaveInstanceState() - } - override fun onResume() { super.onResume() if (browsingModeManager.mode == BrowsingMode.Private) { diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeScreenViewModel.kt b/app/src/main/java/org/mozilla/fenix/home/HomeScreenViewModel.kt index 3c0b80149b..8fa03b7d7a 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeScreenViewModel.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeScreenViewModel.kt @@ -4,7 +4,6 @@ package org.mozilla.fenix.home -import android.os.Parcelable import androidx.lifecycle.ViewModel class HomeScreenViewModel : ViewModel() { @@ -13,8 +12,6 @@ class HomeScreenViewModel : ViewModel() { */ var sessionToDelete: String? = null - var layoutManagerState: Parcelable? = null - /** * Used to remember if we need to scroll to top of the homeFragment's recycleView (top sites) see #8561 * */ diff --git a/app/src/main/java/org/mozilla/fenix/utils/FragmentPreDrawManager.kt b/app/src/main/java/org/mozilla/fenix/utils/FragmentPreDrawManager.kt deleted file mode 100644 index 0160ac7a74..0000000000 --- a/app/src/main/java/org/mozilla/fenix/utils/FragmentPreDrawManager.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* 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.fenix.utils - -import androidx.core.view.doOnPreDraw -import androidx.fragment.app.Fragment -import androidx.lifecycle.lifecycleScope -import kotlinx.coroutines.launch - -/** - * Helper class that allows executing code immediately before [Fragment]s View being drawn. - */ -class FragmentPreDrawManager( - private val fragment: Fragment -) { - init { - fragment.postponeEnterTransition() - } - - fun execute(code: suspend () -> Unit) { - fragment.view?.doOnPreDraw { - fragment.viewLifecycleOwner.lifecycleScope.launch { - code() - fragment.startPostponedEnterTransition() - } - } - } -} diff --git a/app/src/test/java/org/mozilla/fenix/utils/FragmentPreDrawManagerTest.kt b/app/src/test/java/org/mozilla/fenix/utils/FragmentPreDrawManagerTest.kt deleted file mode 100644 index 2515bfe4d5..0000000000 --- a/app/src/test/java/org/mozilla/fenix/utils/FragmentPreDrawManagerTest.kt +++ /dev/null @@ -1,33 +0,0 @@ -/* 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.fenix.utils - -import androidx.core.view.OneShotPreDrawListener -import androidx.fragment.app.Fragment -import io.mockk.mockk -import io.mockk.verify -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.ObsoleteCoroutinesApi -import kotlinx.coroutines.test.runBlockingTest -import org.junit.Test - -@ObsoleteCoroutinesApi -@ExperimentalCoroutinesApi -class FragmentPreDrawManagerTest { - private fun doNothing() { /*noop*/ } - - @Test - fun `execute doOnPreDraw`() { - runBlockingTest { - val fragmentMock = mockk(relaxed = true) - val fragmentPreDrawManager = FragmentPreDrawManager(fragmentMock) - val listener = OneShotPreDrawListener.add(fragmentMock.view!!) { mockk() } - - verify { fragmentMock.postponeEnterTransition() } - fragmentPreDrawManager.execute { doNothing() } - verify { fragmentMock.view?.viewTreeObserver?.addOnPreDrawListener(listener) } - } - } -}