Merge pull request #6681 from vector-im/fix/mna/leak-tab-layout-mediator

[FTUE] Memory leak on FtueAuthSplashCarouselFragment
This commit is contained in:
Maxime NATUREL 2022-08-03 14:18:41 +02:00 committed by GitHub
commit bfd9dcbca2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

1
changelog.d/6680.misc Normal file
View File

@ -0,0 +1 @@
[FTUE] Memory leak on FtueAuthSplashCarouselFragment

View File

@ -52,6 +52,8 @@ class FtueAuthSplashCarouselFragment @Inject constructor(
private val buildMeta: BuildMeta,
) : AbstractFtueAuthFragment<FragmentFtueSplashCarouselBinding>() {
private var tabLayoutMediator: TabLayoutMediator? = null
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentFtueSplashCarouselBinding {
return FragmentFtueSplashCarouselBinding.inflate(inflater, container, false)
}
@ -61,10 +63,19 @@ class FtueAuthSplashCarouselFragment @Inject constructor(
setupViews()
}
override fun onDestroyView() {
tabLayoutMediator?.detach()
tabLayoutMediator = null
views.splashCarousel.adapter = null
super.onDestroyView()
}
private fun setupViews() {
val carouselAdapter = carouselController.adapter
views.splashCarousel.adapter = carouselAdapter
TabLayoutMediator(views.carouselIndicator, views.splashCarousel) { _, _ -> }.attach()
tabLayoutMediator = TabLayoutMediator(views.carouselIndicator, views.splashCarousel) { _, _ -> }
.also { it.attach() }
carouselController.setData(carouselStateFactory.create())
val isAlreadyHaveAccountEnabled = vectorFeatures.isOnboardingAlreadyHaveAccountSplashEnabled()