MVC, MVP, MVVM and now… MVI (Model View Intent), an architecture pattern that developers choose for new Android projects. Why? Android Applications need to grow and include more features, and devs need to have a maintainable, testable and scalable architecture - MVI is a great approach for that.
- Model: represents the view state, contains all the information we need to bind a view.
- View: it’s the UI - when we listen to user and system interactions and show the information we have as state.
- Intent: this is the user or system actions that could change the state of the view.
Example: We have a screen with a button and a list, when a user clicks on the button we display a user list. The intent will be the button click, the model will represent: loading, user list data and error states. The view will be the UI with the button and user list view rendered by the content state with the users information.
- Unidirectional data flow
- State persists during the lifecycle of views
- Immutable models
- Easy to debug and test
The Kotlin team has done a great job providing Kotlin libraries/tools to use in this MVI approach that helps us to have more Kotlin code than Android code when we are in a moment where all mobile apps could be a multi platform app at any time or be reused into a new app.
Doing a good setup for MVI code is mandatory - implementing MVI could take time to code, to think about, how is the structure to work on, etc. CodigoDelSur is focusing on that and is implementing a base setup to use in our upcoming Android projects.