mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-17 15:26:23 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/14903 - Prevent BrowserFragment's view leak
This commit is contained in:
parent
4af151c433
commit
ee9bd92708
@ -54,6 +54,7 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler {
|
||||
private val windowFeature = ViewBoundFeatureWrapper<WindowFeature>()
|
||||
|
||||
private var readerModeAvailable = false
|
||||
private var openInAppOnboardingObserver: OpenInAppOnboardingObserver? = null
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
@ -159,15 +160,16 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler {
|
||||
}
|
||||
session?.register(toolbarSessionObserver, viewLifecycleOwner, autoPause = true)
|
||||
|
||||
if (settings.shouldShowOpenInAppBanner) {
|
||||
session?.register(
|
||||
OpenInAppOnboardingObserver(
|
||||
if (settings.shouldShowOpenInAppBanner && session != null) {
|
||||
openInAppOnboardingObserver = OpenInAppOnboardingObserver(
|
||||
context = context,
|
||||
navController = findNavController(),
|
||||
settings = settings,
|
||||
appLinksUseCases = context.components.useCases.appLinksUseCases,
|
||||
container = browserToolbarView.view.parent as ViewGroup
|
||||
),
|
||||
)
|
||||
session.register(
|
||||
openInAppOnboardingObserver!!,
|
||||
owner = this,
|
||||
autoPause = true
|
||||
)
|
||||
@ -188,6 +190,16 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler {
|
||||
subscribeToTabCollections()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
// This observer initialized in onStart has a reference to fragment's view.
|
||||
// Prevent it leaking the view after the latter onDestroyView.
|
||||
if (openInAppOnboardingObserver != null) {
|
||||
getSessionById()?.unregister(openInAppOnboardingObserver!!)
|
||||
openInAppOnboardingObserver = null
|
||||
}
|
||||
}
|
||||
|
||||
private fun subscribeToTabCollections() {
|
||||
Observer<List<TabCollection>> {
|
||||
requireComponents.core.tabCollectionStorage.cachedTabCollections = it
|
||||
|
Loading…
Reference in New Issue
Block a user