ViewBinding-ktx
ViewBinding-ktx
make easy to use ViewBinding.
DataBinding-ktx is here.
Overview
ViewBinding-ktx
provideswithBinding
method accessing thebinding
variable by lambda.ViewBinding-ktx
providesviewBinding
method accessing thebinding
variable by delegated property.
Usage
Lambda
// no reflection
withBinding(ViewBindingActivityBinding::bind) { binding ->
}
// reflection
withBinding<ViewBindingActivityBinding> { binding ->
}
Delegated Property
private val binding by viewBinding(ViewBindingActivityBinding::bind) // no reflection
private val binding: ViewBindingActivityBinding by viewBinding() // reflection
Note:
In Fragment, When fragment's view is destroyed, an IllegalStateException is thrown on accessing the binding property.
If you access the binding property when fragment's view may be destroyed, you must use the Lambda way above.
Gradle
android {
buildFeatures {
viewBinding true
}
}
repositories {
maven { url "https://www.jitpack.io" }
}
dependencies {
implementation 'com.github.wada811:ViewBinding-ktx:x.y.z'
}
License
Copyright (C) 2020 wada811
Licensed under the Apache License, Version 2.0