Posts

Showing posts with the label fragment-backstack

How to copy YouTube's app navigation logic

How to copy YouTube's app navigation logic I want to implement in my app navigation logic like in Youtube app. (BottomNavigationView + Fragment management). I want this, because these fragments are heavy, so I want them to be lazy initialized and then stored in backstack, I feel like YouTube is doing it this way. I have implemented BottomNagivationView but I have problems with Fragment Management. My code: bottomNavigationView.setOnTabSelectedListener { position, _ -> setFragment(OnlinePageFragment.Page.values()[position]) } where Pages is enum enum class Page(index: Int, val klass: Class<*>) { ONE(0, OnePageFragment::class.java), TWO(1, TwoPageFragment::class.java), THREE(2, ThreePageFragment::class.java) } and here is my setFragment function fun setFragment(page: OnlinePageFragment.Page) { var fragment: Fragment? = supportFragmentManager.findFragmentByTag(page.klass.name) val tag = page.klass.name if (fragment == null) ...