Search code examples
androidmortarsquare-flow

Using Flow & Mortar with ViewPager


I'm in the process of writing an app using Flow and Mortar. I'm having trouble figuring out how to use this when it comes to a view pager with tabs.

Only way I can think of is to treat the ViewPager screen as a single screen, and end up using Fragments to build it. But the whole point of using Flow & Mortar is to get rid of Fragments and simplify the lifecycle.

Any help is appreciated. Thanks.


Solution

  • I made a view pager example, up to date with Mortar and Flow versions (based on adapter from Kirill Boyarshinov).
    I don't copy past the code in the answer, because it's too big and it would be less readable (if it breaks the SO rules, let me know and I'll edit the answer).

    View pager adapter : https://github.com/lukaspili/Mortar-Flow-Dagger2-demo/blob/master/app/src/main/java/com/lukaspili/mortardemo/app/adapter/SlidePagerAdapter.java

    Screen containing the viewpager : https://github.com/lukaspili/Mortar-Flow-Dagger2-demo/blob/master/app/src/main/java/com/lukaspili/mortardemo/ui/screen/SlidesScreen.java

    Screen as page of the viewpager : https://github.com/lukaspili/Mortar-Flow-Dagger2-demo/blob/master/app/src/main/java/com/lukaspili/mortardemo/ui/screen/SlidePageScreen.java