/ViewBindingKTX

The most comprehensive utils of ViewBinding.(最全面的 ViewBinding 工具,支持 Kotlin 和 Java 用法,支持拓展函数和基类改造,支持 BRVAH)

Primary LanguageKotlinApache License 2.0Apache-2.0

ViewBindingKTX

English | 中文

ViewBinding reduces exceptions caused by id or type errors, which are recommended by both Google officials and Jake Wharton, but it can be a bit cumbersome to use, so this library can help you use ViewBinding with as little code as possible in any usage scenario.

Feature

  • Support for the usage of Kotlin and Java
  • Support for the usage of reflection and non-reflection
  • Support to modify your base class to support ViewBinding
  • Support for BaseRecyclerViewAdapterHelper
  • Support for Activity, Fragment, Dialog, Adapter
  • Support automatic release of binding class instance in Fragment
  • Support for custom combination view
  • Support for TabLayout to set custom view
  • Support for NavigationView to set header view
  • Support for DataBinding to automatically set the lifecycle owner

Gradle

Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url 'https://www.jitpack.io' }
    }
}

Add dependencies and configurations:

android {
    buildFeatures {
        viewBinding = true
    }
}

dependencies {
    // The following are optional, please add as needed
    implementation 'com.github.DylanCaiCoding.ViewBindingKTX:viewbinding-ktx:1.2.2'
    implementation 'com.github.DylanCaiCoding.ViewBindingKTX:viewbinding-nonreflection-ktx:1.2.2'
    implementation 'com.github.DylanCaiCoding.ViewBindingKTX:viewbinding-base:1.2.2'
    implementation 'com.github.DylanCaiCoding.ViewBindingKTX:viewbinding-brvah:1.2.2'
}

Wiki

Kotlin usage

Java usage

Others

Change log

Releases

Thanks

Thanks ViewBindingPropertyDelegate for providing an idea without reflection

License

Copyright (C) 2020. Dylan Cai

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.