-
-
Notifications
You must be signed in to change notification settings - Fork 495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pattern for data binding #822
Comments
@AllanWang have you had a look at |
This pattern is actually pretty generic, so long as there is a way to get the binding from the layout res. I probably won't be looking at ViewBinding until it makes it to AS Beta, but there is a chance it will still work. If all they expose is the inflate method, I would be pretty disappointed |
This can probably be closed, as it's really here in case people search for it and want information. I'm testing integration with ViewBinding here: Essentially, it seems like we can get the view information from the binding instead of a custom viewholder, and if we implement equality through the use of data classes for models, we get diffs out of the box too. All that is left is to use a single IItem model. It is annoying that you have to provide the binding yourself, whereas with data binding there is a generic loader that can take in the layoutRes you provide. In this case, the layoutRes is a bit redundant, but is still used to validate event hooks. |
Perhaps you would be interested in doing a sample activity in the sample app to showcase this? if we somehow can do that more generic or so and pack it, then we could also set-up a new additional extension :) |
I'm in the process of testing now. It could be even more generic by supporting any class with a |
…usage with viewbinding / databinding - update to AS 4.0.0-alpha09 for viewbinding / databinding - add compileOnly dependency for viewBinding interface - use iconItem from viewBinding in the sample app - FIX / REGARDING #822
Please have a look at the new data binding module :) perhaps this suites all the needs |
Not an issue, but just wanted to post this to help with others using data binding. If it proves to be useful, it could also be added as another submodule.
The general contents are here, but the idea is that with data binding, we can get the view ids from the layout id, and we no longer need to make a custom ViewHolder. This also avoids the need for non generic adapters.
ViewHolders however are useful for cases like event hooks, where we need to distinguish between the types. This binding pattern uses a companion object to keep track of that layout res instead.
Usage example:
Binding and unbinding signatures extend the data binding, so view access is easy, and the model can be accessed from
data
. So long as it is a data class, equality and hash are also defined, so diffs work out of the box.Id type defaults to layout res, though that is a person design decision.
The text was updated successfully, but these errors were encountered: