Problem
Hi! I would like to implement a custom UI component with some basic logic for Android in MvvmCross so it would be reusable across different layouts. What we were doing so far is using a BaseActivity with the components that would be reused and inheriting from it (for example, for the toolbar). Some time later, the need to apply different toolbars in some activities appeared, so we had two choices there:
- Put more than one toolbar inside the AppBarLayout in the BaseActivity and each activity controller which inherits from BaseActivity would set the visibility for the toolbar it would want to use (including use more than one toolbar, if necessary).
- Make another parent class (something like BaseActivityWithOtherHeader) for each different combination of headers and each activity would inherit from the corresponding BaseActivity.
We took the first approach, but neither of them would be maintanable for much time, for obvious reasons...
Hypothesis
So, from my perception, the best approach for this is to create an .axml file in which I specify the layout of the component and (maybe) create a ViewController in which I apply Fluent Binding to the ViewModel containing the logic of said component. This way, the logic is shared across different platforms. Also, if I'm not mistaken, this approach would let me an my peers include it in our Activities by simply using the <include> tag (and perhaps just a declaration on the ViewController of the Activity instead of the whole logic, or something like that), which would comply with the Don't Repeat Yourself paradigm, providing a cleaner code and faster development.
But I couldn't find any examples nor guidelines for implementing Reusable Components with MvvmCross, either by googling or in the documentation...
What I found was only this question, which refers to and old version of MvvmCross, and apparently there is no more an IMvxLayoutInflater class, nor does theIMvxBindingContext object has the BindingInflate() method...
Questions
So, I have two questions regarding this matter:
- Is there a better approach for this than the proposed above, considering I am using MvvmCross 6.2.1?
- Could you provide any examples for creating any custom reusable component with MvvmCross 6.x, be it with the proposed method or another one not mentioned in the first section?