Skip to content

Conversation

@karlsonj
Copy link

This adds the ability to have viewmodels that contain other viewmodels. In the Android layout files, you might have, say, a (shared) widget that manages phone number entry and validation, and a viewmodel that contains it and manages the validation of the rest of a form. Something like this:

<layout>
  <data>
    <variable name="formViewModel" type="com.company.FormViewModel"/>
    <variable name="phoneViewModel" type="com.company.PhoneViewModel"/>
  </data>
  <LinearLayout>
    <!-- Bound components for the form... -->
    <include layout="@layout/phoneentry" app:viewModel="@{phoneViewModel}"/>
  </LinearLayout>
</layout>

This PR allows you to create an outer FormViewModel that extends AggregateViewModel and a shared PhoneViewModel that extends SubViewModel and is aggreagated within the FormViewModel:

class FormViewModel extends AggregateViewModel {

  PhoneViewModel phoneViewModel = new PhoneViewModel();

  class FormViewModel() {
    addSubviews(phoneViewModel);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant