I mainly learned Android development with Jetpack Compose and MVI architecture. Now for learning purposes I am trying to understand the differences between MVI and MVVM and how MVVM could look like with Jetpack Compose.
I've read that one of the key features of MVVM is two way databinding. On Android however, two way data binding seems to be only available for the "old xml UI" world. Could MVVM still be used with Jetpack Compose? How would that look like in code?
Yes, MVVM can be used with Jetpack Compose, even without two-way data binding.
ViewModels in MVVM typically skip the complexity of actors, reducers, and similar constructs used in MVI, following a more streamlined approach. However, it’s worth noting that nothing stops developers from structuring a ViewModel in a MVI way if they prefer to do so.
Besides this, another small difference that sometimes comes up is in how the View communicates with the ViewModel, using independent methods for each interaction (
onEmailInputUpdated(…),onSubmitSelected(), etc.) compared to MVI where all of these would be modelled as a sealed class and passed through a single method to be processed.In any case, both architectures depend on Unidirectional Data Flow (UDF). In Compose, that just means observing state changes in the ViewModel and recomposing the UI accordingly.
Two-way data binding, while useful as a sort of productivity tool for not having to manually update each view from your activity/fragment, doesn't really fundamentally affect the architectural communication between the View and the ViewModel. Whether you use data binding or not (which is deprecated in many contexts), it doesn't impact the core principles of MVVM.