2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-11 13:11:01 +00:00

Closes #17443: IllegalStateException in startPostponedEnterTransition on HomeFragment

This commit is contained in:
Christian Sadilek 2021-01-14 11:59:37 -05:00
parent d9ff67f330
commit f8359e72bf
5 changed files with 0 additions and 99 deletions

View File

@ -5,9 +5,7 @@
package org.mozilla.fenix.browser package org.mozilla.fenix.browser
import android.content.Context import android.content.Context
import android.os.Bundle
import android.os.StrictMode import android.os.StrictMode
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.content.res.AppCompatResources import androidx.appcompat.content.res.AppCompatResources
@ -54,17 +52,6 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler {
private var openInAppOnboardingObserver: OpenInAppOnboardingObserver? = null private var openInAppOnboardingObserver: OpenInAppOnboardingObserver? = null
private var pwaOnboardingObserver: PwaOnboardingObserver? = null 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") @Suppress("LongMethod")
override fun initializeUI(view: View): Session? { override fun initializeUI(view: View): Session? {
val context = requireContext() val context = requireContext()

View File

@ -113,7 +113,6 @@ import org.mozilla.fenix.settings.SupportUtils
import org.mozilla.fenix.settings.SupportUtils.SumoTopic.HELP import org.mozilla.fenix.settings.SupportUtils.SumoTopic.HELP
import org.mozilla.fenix.settings.deletebrowsingdata.deleteAndQuit import org.mozilla.fenix.settings.deletebrowsingdata.deleteAndQuit
import org.mozilla.fenix.theme.ThemeManager import org.mozilla.fenix.theme.ThemeManager
import org.mozilla.fenix.utils.FragmentPreDrawManager
import org.mozilla.fenix.utils.ToolbarPopupWindow import org.mozilla.fenix.utils.ToolbarPopupWindow
import org.mozilla.fenix.utils.allowUndo import org.mozilla.fenix.utils.allowUndo
import org.mozilla.fenix.whatsnew.WhatsNew import org.mozilla.fenix.whatsnew.WhatsNew
@ -170,7 +169,6 @@ class HomeFragment : Fragment() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
postponeEnterTransition()
bundleArgs = args.toBundle() bundleArgs = args.toBundle()
lifecycleScope.launch(IO) { lifecycleScope.launch(IO) {
if (!onboarding.userHasBeenOnboarded()) { if (!onboarding.userHasBeenOnboarded()) {
@ -339,19 +337,7 @@ class HomeFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
FragmentPreDrawManager(this).execute {
homeViewModel.layoutManagerState?.also { parcelable ->
sessionControlView!!.view.layoutManager?.onRestoreInstanceState(parcelable)
}
homeViewModel.layoutManagerState = null
// We have to delay so that the keyboard collapses and the view is resized before the
// animation from SearchFragment happens
delay(ANIMATION_DELAY)
}
observeSearchEngineChanges() observeSearchEngineChanges()
createHomeMenu(requireContext(), WeakReference(view.menuButton)) createHomeMenu(requireContext(), WeakReference(view.menuButton))
createTabCounterMenu(view) createTabCounterMenu(view)
@ -654,12 +640,6 @@ class HomeFragment : Fragment() {
}.show() }.show()
} }
override fun onStop() {
super.onStop()
homeViewModel.layoutManagerState =
sessionControlView!!.view.layoutManager?.onSaveInstanceState()
}
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
if (browsingModeManager.mode == BrowsingMode.Private) { if (browsingModeManager.mode == BrowsingMode.Private) {

View File

@ -4,7 +4,6 @@
package org.mozilla.fenix.home package org.mozilla.fenix.home
import android.os.Parcelable
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
class HomeScreenViewModel : ViewModel() { class HomeScreenViewModel : ViewModel() {
@ -13,8 +12,6 @@ class HomeScreenViewModel : ViewModel() {
*/ */
var sessionToDelete: String? = null 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 * Used to remember if we need to scroll to top of the homeFragment's recycleView (top sites) see #8561
* */ * */

View File

@ -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()
}
}
}
}

View File

@ -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<Fragment>(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) }
}
}
}