Closed shostko closed 4 years ago
I thought about that improvement 2 days ago. I've just checked your proposal and my own solution. The second one is better and require less code. The library already has ability to create a ViewBinding without reflection using
fun <F : Fragment, T : ViewBinding> F.viewBinding(viewBinder: (F) -> T): ViewBindingProperty<F, T>
but your proposal demonstrate that possibility to send method references will be better than lambda
Could you please share your solution? And describe the difference? (Which does not include implementing (F) -> T lambda on each fragment)
BTW of course it is possible to reduce amount of code and leave only one additional extension method:
fun <F : Fragment, T : ViewBinding> F.viewBinding(viewBinder: (View) -> T, viewFinder: (F) -> View = Fragment::requireView): ViewBindingProperty<F, T> {
return viewBinding { viewBinder(viewFinder(this)) }
}
I just tried to follow style of code already exists in the project.
You are right about my solution. I've added inline for function type to reduce number of created objects
Yeah. it is also a good idea. When are you going to publish new version with this update?
On this week. I am working on improvements right now
The changes are in develop
branch
Thanks for pushing this code.
I'm using very similar way to associate ViewBinding with Fragment but have slightly different way to do that without reflection.
This PR adds same possibilities to ViewBindingPropertyDelegate:
It also contains a possibility to bind not only on root fragment view (see ProfileFragment2.kt):