Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upcoming breaking changes in 3.1 canary 6 onwards. #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

PrashamTrivedi
Copy link

Android studio 3.1 Canary 6 introduces Databinding compiler which introduces new changes which are breaking for library consumers. As per Release Notes binding code is generated and packaged in AAR, and dependent modules are no longer re-generating library bindings.

Also as per documentation this changes are backward incompatible, means consumers of Databinding v2 can't use library or code generated against Databinding v1.

Another change as stated here data binding inflation methods (inflate and setContentView etc...) will return nullable bindings (Null in case of layout is not binding layout). Which is breaking change for consumers.

This pull request facilitates both above stated changes, but I suggest be cautious as the changes are for alpha release of plugin.

 Databinding v2
@@ -10,7 +11,18 @@ android {
dataBinding.enabled true
}

afterEvaluate {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a workaround as suggested by Yigit Boyar here, and actual change here

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not needed anymore, at least in 3.1 beta 1

@@ -35,7 +35,7 @@ class LastAdapter(private val list: List<Any>,
private val DATA_INVALIDATION = Any()
private val callback = ObservableListCallback(this)
private var recyclerView: RecyclerView? = null
private var inflater: LayoutInflater? = null
private lateinit var inflater: LayoutInflater
Copy link
Author

@PrashamTrivedi PrashamTrivedi Dec 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it lateinit as I felt the real nature of this is late initialization, and won't be nullable ever after.

@nitrico
Copy link
Owner

nitrico commented Jan 21, 2018

Wow! Thank you so much for all the information! I'll keep all that in mind when the final version is released. :)

@@ -19,6 +19,6 @@ package com.github.nitrico.lastadapter
import android.databinding.ViewDataBinding
import android.support.v7.widget.RecyclerView

open class Holder<B : ViewDataBinding>(val binding: B) : RecyclerView.ViewHolder(binding.root) {
open class Holder<B : ViewDataBinding>(val binding: B?) : RecyclerView.ViewHolder(binding?.root) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the nullable binding variable will break a lot of existing code. You can/should even remove it as DataBindingUtil.inflate doesn't return a nullable binding (anymore?)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They should've reverted this change. I don't have the link handy but in one of the issue in issue tracker Yigit Boyar mentioned that Databinding is supposed to be null in case the layout is not binding layout. And this was Working as intended type of thing,

At this point

  1. I am awaiting official confirmation in release notes
  2. At work I can still see Databinding.inflate() retirns Binding! class. Which can be null from Java if not from kotlin.
  3. This comment increases confusion a lot. Coming from DataBindingUtil.java 3.1.0beta1.
// @Nullable don't annotate with Nullable. It is unlikely to be null and makes using it from
    // kotlin really ugly. We cannot make it NonNull w/o breaking backward compatibility.

I will wait for official release notes around databinding changes before deciding to proceed on this change.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, makes sense!

Even if it'll be nullable we might work around that by checking for null before creating the Holder-instance and optionally throw an exception if it the binding is null. That way we wouldn't break backward compatibility with this library.

Copy link
Author

@PrashamTrivedi PrashamTrivedi Jan 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optionally throw an exception

I am against throwing an exception in this case.

Reason(s)

  1. Mostly this lib is being used with normal databinding, which means users have to handle binding nullability in places where this library is not used.

  2. Most thrown exception is swallowed without having any actions. Based on this I fear throwing exception won't change anything except adding try catch block, mostly to log exceptions. (Even we do this in 80% cases)

break backward compatibility with this library.

With point 1 above, I feel backword compatibility is already broken. (Esp backward compatibility from databinding v2 to v1)

Anyways, I don't mind if the flow goes either way (Having nullable bindings or throwing exception),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Let's see - maybe the google devs decide to handle this case (the user tries to load a non-bindable layout) themselves to sort this out.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update on null-ability on databinding, Here is the issue we reported w.r.t. nullability, based on their response what they did is not to force null-ability when we're using kotlin. I don't know how this changes our discussion but I am putting this as reference link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants