Closed AlexTrotsenko closed 3 years ago
@AlexTrotsenko I updated the library's code. In ViewBinding-ktx v1.2.1, you can define base class like below.
open class BaseViewBindingFragment<T : ViewBinding>(
@LayoutRes contentLayoutId: Int,
bind: (View) -> T
) : Fragment(contentLayoutId) {
protected val binding: T by viewBinding(bind)
}
Thank you.
I see, that https://github.com/wada811/DataBinding-ktx shows example of base class implementation in the Readme.
I believe following example might be helpful to add to the readme of viewBinding as well:
Base
Child
Another option would be adding such base classes to the lib itself and let be removed by the R8/Dexguard if it's not used. It could help to reduce the amount of the boilerplate code even further.
P.S. @wada811 do you think it might be possible to change the api in order to avoid this reified-related work-around? As far as I see,
reified
generic type is only used for no-argument method invocation and absolutely not need for the case whenbind
producer is explicitly passed as an argument. Thus splitting this method in two different methods should solve an issue.