MVI For android
![MVI For android](/content/images/size/w960/2024/01/1-16cq9yo7-e7zbjjwqsqr8a.png)
I start working with it because I need to implement it in my code so when I start doing a feature which have many deferent actions in it the screen start becoming bigger,I feel the mvvm start having spaghetti code, I end up having many live data in it, so I have to observer on many of them,
also I don’t want to change my all code base to mvi, so I start searching to see if I can use deferent presentation architecture in the project so
I find out that Yes you can do it and this is a good way to do it .
I’m still using mvvm and I use the presentation architecture depends on the screen and the UseCases in it.
So if the screen need to have to have deferent UseCases I do it with MVI
And the screen which have less use cases like one or two and the cases is easy to be tested and it just need to request and show something small I do it with MVVM.
Now I want to share with you the things I watched and read to learn it.
With MVI all of the use cases are covered and you observe in one place and render your UI from this place and it’s also good to separate the ui from the logic, it’s easy to test, the code is clean and readable and maintainable.
How It work in simple Way
- Intent is converted to actions
- Actions is converted to model
- Model is responsible for data this part is also separated and you can test alone and you can mock
- The Model is converted to Result
- The Result is converted to State
If you just want to make it more simple you push and Intent to the model and the model will be responsible to push for you a ViewState thats it this pattern is taken from Web from frameworks Like Redux and Cycle JS
One of the best articles to read
https://www.linkedin.com/pulse/mvi-pattern-android-4-steps-ahmed-adel-ismail/
Also you can start with this talk.
https://www.youtube.com/watch?v=PXBXcHQeDLE&t=1525s
https://github.com/oldergod/android-architecture
In this talk he is using RxJava but also there is some easier and faster implementation.
You can also use A framework Like roxie
https://github.com/ww-tech/roxie
https://proandroiddev.com/unidirectional-data-flow-with-roxie-bec546c18598
#android #MVI #GOOGLE #development #UI #testing
Member discussion