Combining Views and View Models

LAST EDIT May 17 2021

MessageListHeaderView, MessageListView, MessageInputView, and corresponding ViewModels are separate components that usually will be displayed on the same screen. They work great without knowing about each other, but some of the chat features require passing data between different components

Handling threads

Copied!

MessageListViewModel contains information about the current mode which can be changed by interacting with its view. Information needs to be passed to both MessageListHeaderViewModel and MessageInputViewModel which handle different modes. You can combine those view models in the following way:

Editing message

Copied!

MessageListView gives a possibility to set a handler that will be responsible for editing message action. The handler should pass a message to MessageInputViewModel which is responsible for displaying it in MessageInputView:

Handling back button clicks

Copied!

MessageListHeaderView gives a possibility to override the back button behaviour which should be combined with MessageListViewModel which can handle back button clicks considering whether the user is in thread mode or not. You can easily combine those two components in the following way: