androidbroadcast / ViewBindingPropertyDelegate

Make work with Android View Binding simpler
https://proandroiddev.com/make-android-view-binding-great-with-kotlin-b71dd9c87719
Apache License 2.0
1.42k stars 102 forks source link

Nullable views #54

Closed isalig closed 3 years ago

isalig commented 3 years ago

Can we access views in safe style via Elvis operator? It could be helpful in some cases during migration from Kotlin synthetics

kirich1409 commented 3 years ago

Please, provide code sample

isalig commented 3 years ago

We save view state in onSaveInstanceState sometimes. Of course this is not the best solution, but it's already written at many places. And Kotlin synthetics were providing safe view access like view?.doSomething(). Can we do something like binding.view?.property. It could make migration easier for projects with code like that:

override fun onSaveInstanceState(outState: Bundle) {
    recyclerView
      ?.layoutManager
      ?.onSaveInstanceState()
      ?.let { state -> outState.putParcelable(SCROLL_STATE_KEY, state) }
    super.onSaveInstanceState(outState)
 }
kirich1409 commented 3 years ago

ViewBinding generated by Android Gradle Plugin. I can't change it

isalig commented 3 years ago

And what about nullable ViewBinding property?

kirich1409 commented 3 years ago

It will break the work of the library for users. You can make a fork and do what you need