ViewBinding Ktx Save

ViewBinding-ktx make easy to use ViewBinding.

Project README

ViewBinding-ktx

ViewBinding-ktx makes it easy to use ViewBinding.

DataBinding-ktx is here.

Overview

  • ViewBinding-ktx provides the withBinding method accessing the binding variable by lambda.
  • ViewBinding-ktx provides the viewBinding method accessing the binding variable by delegated property.

Usage

// 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 the fragment's view is destroyed, an IllegalStateException is thrown on accessing the binding property.
If you access the binding property when the fragment's view may be destroyed, you must use the Lambda way above.

Gradle

Maven Central

android {
    buildFeatures {
        viewBinding true
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'com.wada811.viewbindingktx:viewbindingktx:x.y.z'
}

Migrations

3.0.0

dependencies

-    implementation 'com.github.wada811:ViewBinding-ktx:x.y.z'
+    implementation 'com.wada811.viewbindingktx:viewbindingktx:x.y.z'

package

-import com.wada811.viewbinding
+import com.wada811.viewbindingktx

License

Copyright (C) 2020 wada811

Licensed under the Apache License, Version 2.0

Open Source Agenda is not affiliated with "ViewBinding Ktx" Project. README Source: wada811/ViewBinding-ktx
Stars
37
Open Issues
9
Last Commit
2 weeks ago
License

Open Source Agenda Badge

Open Source Agenda Rating