Hi guys! I have a question regarding MVVM.
Let’s say I have a ViewPager that has 3 pages and has automatic scrolling feature. (this viewpager goes back to page 1 when reaching page 3). The auto scrolling feature is PAUSED everytime the viewpager receives a touch action.
Now, should the logic of setting view pager’s current item to 1 if it reaches 3, and the pausing of auto scroll when view pager receives touch event RESIDE in ViewModel?
In my understanding. Purely UI logic can stay in activity/fragment. Logic that can reside in ViewModel can include enabling/disabling buttons (depending on the input), validating inputs, etc.
Any inputs are greatly appreciated!
m
Marko Mitic
08/09/2019, 10:04 AM
Why no simple smile here?
i
ignus
08/09/2019, 10:05 AM
it should be handled by view
m
Melih Aksoy
08/09/2019, 10:16 AM
It can be situational - for example if you’re using databinding and passing VM to assign fields to views, it’s not uncommon VM has view related methods. IMO activity / fragment should handle interaction but not logic of any kind.
👍 1
c
Camilo
08/09/2019, 3:35 PM
I would personally fire an event from the UI to the view model when the Scroll reaches the bottom and then the view model determining the logic states to publish to the view an event to go up to the view telling it to scroll to the top…that way you can set up unit test on your view model as well as keep all logic in one place