Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Nested Fragments

Avatar for Sajal Sajal
January 19, 2019

Nested Fragments

A summary of challenges we faced while creating a truly scalable dynamic home page of the new zomato app.
The talk takes the user through the journey of the problem we had at our hands, the way we looked at it, the challenges we faced and finally what we ended up creating.

Android Challenges(Topics) that this talk covers
1. FragmentPagerAdapter
2. FragmentStatePagerAdapter
3. ViewStubs

Avatar for Sajal

Sajal

January 19, 2019

More Decks by Sajal

Other Decks in Programming

Transcript

  1. New Zomato App • Feature outline ◦ Bottom Navigation Tabs

    ◦ Each tab could/ could not host nested content. • Dynamic Content ◦ Both bottom tabs and the nested content can be vastly different dependent on plethora of parameters like city / user / product launches / promotions etc.
  2. Dissecting the problem • Defining the basic premise of parent

    child content holders • Possible re-use of “content” holder ◦ Fragments .. Nested ? ◦ PagerAdapter ? -- Choices?
  3. What we need • Destruction of fragments when not in

    use • Fragment state management • Invalidate reused fragments
  4. FragmentPagerAdapter - The issue Fragment A,B,C Fragment B,C,D notifyDataSetChanged() B

    and C are unaware of the change. Invalidation may/ may not be required.
  5. Need to set ViewPager offset • Bad UX. • Multiple

    calls to server on navigating through app.
  6. ViewStubs ftw * A ViewStub is an invisible, zero-sized View

    that can be used to lazily inflate layout resources at runtime. * abstract fun getLayoutResourceId(): Int
  7. Nested Lazy Inflation onCreateView() of Parent fragment onViewInflated() of Parent

    fragment Creation of ViewPager of Parent fragment onCreateView() of child fragments within offset onViewInflated() of SELECTED FRAGMENT only and so on..