MVVM & Nested Fragments/Views: ViewModel Contracts
summary
Claim: define small interface-based ViewModel Contracts that fragments expect and pass the parent ViewModel class in their arguments so fragments obtain the parent instance via ViewModelProvider and cast it to the contract. Uses LiveData, ViewModelProvider/ViewModelFactory, LiveData transformations and simple extension helpers. Built a registration flow (username email interests + persistent progress card) and refactor removes the activity as mediator, yields plug-and-play reusable fragments and clearer state mapping instead of a monolithic shared ViewModel. Sample code on GitHub; approach works in production.
AI-written summary · about
chapters (8)
- 0:00Introduction and motivation
- 1:07Fragment communication challenges
- 5:38Registration flow example
- 8:47MVVM and ViewModel basics
- 12:36ViewModel contracts concept
- 16:24Implementation steps
- 21:59Key benefits and takeaways
- 23:06Resources and conclusion
related talks
28mLifecycle, LiveData, ViewModels - The inner wiring
39mACTIVITIES AND FRAGMENTS ARE NOT MVX VIEWS
23mLifecycle, LiveData, Viewmodels - The inner wiring
41mViewModels, LiveData and Lifecycles, oh my!
40mComposing ViewModels: Breaking ViewModels into smaller self-contained UI models
35mBreaking Up with Big ViewModels
30mArchitecting an app with MVP and ViewModels
56mYou've been told lies about Fragments
