-
Notifications
You must be signed in to change notification settings - Fork 72
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,4 @@ | |
# org.gradle.parallel=true | ||
|
||
org.gradle.jvmargs=-Xmx2048m | ||
android.databinding.enableV2=true |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
// @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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I am against throwing an exception in this case. Reason(s)
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), There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
internal var created = false | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made it |
||
|
||
private val map = mutableMapOf<Class<*>, BaseType>() | ||
private var layoutHandler: LayoutHandler? = null | ||
|
@@ -90,7 +90,7 @@ class LastAdapter(private val list: List<Any>, | |
override fun onCreateViewHolder(view: ViewGroup, viewType: Int): Holder<ViewDataBinding> { | ||
val binding = DataBindingUtil.inflate<ViewDataBinding>(inflater, viewType, view, false) | ||
val holder = Holder(binding) | ||
binding.addOnRebindCallback(object : OnRebindCallback<ViewDataBinding>() { | ||
binding?.addOnRebindCallback(object : OnRebindCallback<ViewDataBinding>() { | ||
override fun onPreBind(binding: ViewDataBinding) = recyclerView?.isComputingLayout ?: false | ||
override fun onCanceled(binding: ViewDataBinding) { | ||
if (recyclerView?.isComputingLayout ?: true) { | ||
|
@@ -107,8 +107,8 @@ class LastAdapter(private val list: List<Any>, | |
|
||
override fun onBindViewHolder(holder: Holder<ViewDataBinding>, position: Int) { | ||
val type = getType(position)!! | ||
holder.binding.setVariable(getVariable(type), list[position]) | ||
holder.binding.executePendingBindings() | ||
holder.binding?.setVariable(getVariable(type), list[position]) | ||
holder.binding?.executePendingBindings() | ||
@Suppress("UNCHECKED_CAST") | ||
if (type is AbsType<*>) { | ||
if (!holder.created) { | ||
|
@@ -120,7 +120,7 @@ class LastAdapter(private val list: List<Any>, | |
|
||
override fun onBindViewHolder(holder: Holder<ViewDataBinding>, position: Int, payloads: List<Any>) { | ||
if (isForDataBinding(payloads)) { | ||
holder.binding.executePendingBindings() | ||
holder.binding?.executePendingBindings() | ||
} else { | ||
super.onBindViewHolder(holder, position, payloads) | ||
} | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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