Skip to content

Lifecycle-friendly view binding in Kotlin for Conductor.

License

Notifications You must be signed in to change notification settings

hannesstruss/cheesewire

Repository files navigation

⚠️ Deprecated

CheeseWire is deprecated. From Android Gradle Plugin 3.6 on, you should use ViewBinding.

CheeseWire

Lifecycle-friendly view binding in Kotlin for Conductor.

Build Status Maven Central

To use, add a ConductorViewBinder to your base controller:

abstract class BaseController : Controller() {
  protected val views = ConductorViewBinder(this)
}

This can now be used to bind views in your concrete controllers:

class HomeController : BaseController() {
  private val btnLogin: Button by views.bind(R.id.btn_login)
}

during onDestroyView, the view binder is reset, and your views aren't leaked.

See the sample app for an example.

Generic lazy

CheeseWire view binders also provide a generic lazy property delegate which is synchronized with your view property lifecycle. This comes in handy e.g. in combination with RxBinding when you want to avoid calling the RxBinding methods twice on a view:

class MyMviController : BaseController() {
  private val btnLogin: Button by views.bind(R.id.btn_login)
  private val btnSignup: Button by views.bind(R.id.btn_login)

  val intentions by views.lazy {
    Observable.merge(
        btnLogin.clicks().map { Intention.Login },
        btnSignup.clicks().map { Intention.Signup }
    )
  }
}

Download

dependencies {
  implementation 'de.hannesstruss.cheesewire:cheesewire-conductor:0.2'
}

Attributions 🙇

CheeseWire is inspired by the awesome work of ButterKnife, KotterKnife and ButterknifeConductor.

License

Copyright (C) 2017 Hannes Struss

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.

About

Lifecycle-friendly view binding in Kotlin for Conductor.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages