Using Flow & Mortar with ViewPager

In the process of writing the application, I use Flow and Mortar. It's hard for me to figure out how to use this when it comes to viewing tabbed pagers.

The only way I can think of is to view the ViewPager screen as one screen and ultimately use Snippets to create it. But the whole point of using Flow and Mortar is to get rid of fragments and simplify the life cycle.

Any help is appreciated. Thanks.

+5
source share
4 answers

I made an example of a pager, updated with the versions of Mortar and Flow (based on the adapter from Kirill Boyarshinov).
I do not copy the code in the answer because it is too large and it will be less readable (if it violates the SO rules, let me know and I will edit the answer).

Open the 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 viewer: https://github.com/lukaspili/Mortar-Flow-Dagger2-demo/blob/master/app/src/main/java/com/lukaspili/mortardemo/ui/screen/SlidesScreen.java

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

+6
source

I think the PagerAdapter is what you are looking for. It was used to bind View directly to ViewPager without using fragments by overriding instantiateItem(ViewGroup, int) . and ViewGroup is an instance of ViewPager where you can use the add method to directly add the View to it.

+4
source

I made a code snippet with a custom PagerAdapter that controls Mortar screens. You can find it here . But it is deprecated from the current version of Mortar. Hope this helps :)

+4
source

Have you found anything so far? I came across the same case that I did when implementing this, is that I view each section of the viewpager as a view, and not as a β€œscreen” used in Mortar.

Basically, I implemented my custom views for each section and my own speakers (custom-made). This did the trick, but I would like for me to use more of the concept from Mortar in the viewpager.

+3
source

Source: https://habr.com/ru/post/987948/


All Articles