airbnb / mavericks

Mavericks: Android on Autopilot
https://airbnb.io/mavericks/
Apache License 2.0
5.83k stars 500 forks source link

How to make a Settings screen with view animation? #201

Closed bernaferrari closed 5 years ago

bernaferrari commented 5 years ago

I'm having trouble thinking how to make a settings screen using MvRx + Epoxy. It was really simple/easy to work with Groupie, but I can't figure out how to make Epoxy+MvRx work with it.

I want to see content changing/being animated, without the "row being replaced/diffied" which typically happens. I was able to make Epoxy work by changing params inside the clickListener, like: v.item_switch.isChecked = true.

However, when dealing with MvRx, I have to deal with the ViewModel. What should I put there? A bunch of observable SharedPreferences? Nothing? Don't use MvRx for this scenario?

elihart commented 5 years ago

On the Epoxy side the easiest way to animate the view is to use an @ModelView and pass a prop for whether it is toggled. When you rebuild models it will call only that method on the view and the view can animate itself however it wants. Sounds like you're basically already doing that, so what else is giving you problems with Epoxy?

For MvRx, the view model state should contain the boolean values for each option declaring if it is selected or not

bernaferrari commented 5 years ago

lol, I have no idea, but things are working perfectly now, so thanks! Really awesome to make a reactive settings screen!

bernaferrari commented 5 years ago

I'm having this weird issue: https://imgur.com/CFqb0nZ

Sometimes works, sometimes doesn't. I want that animation. When light mode is toggled, the activity restarts. That's why sometimes it works on the video. Any ideas?

elihart commented 5 years ago

hard to say from a video, would be some bug in your source.

bernaferrari commented 5 years ago

That's weird. My source is (currently) really simple.

If you don't matter looking at it, this is the fragment and the ViewModel with this layout. Both together are less than 150 LOC. I don't even know where to go, how to debug it to make sure animation always happens.

It usually works, but not always, specially after switching fragment and when toggling the view that changes both text and switch instead of only switch.