Skip to content

Commit

Permalink
make previous component null in onViewUpdate if component ids are not
Browse files Browse the repository at this point in the history
 equal
  • Loading branch information
flopshot committed Mar 19, 2020
1 parent af463ca commit c2a62f9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions library/src/main/java/com/seannajera/dkouple/ComponentView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@ import androidx.recyclerview.widget.RecyclerView
abstract class ComponentView<Component : com.seannajera.dkouple.Component>(view: View) :
RecyclerView.ViewHolder(view) {

private var cachedComponent: Component? = null

@Suppress("UNCHECKED_CAST")
fun onBind(
previous: com.seannajera.dkouple.Component?,
current: com.seannajera.dkouple.Component
) {
previous as Component?
current as Component
onViewUpdate(previous ?: cachedComponent, current)
cachedComponent = current

val prior = if (previous?.id == current.id) {
previous
} else {
null
}

onViewUpdate(prior, current)
}

abstract fun onViewUpdate(previous: Component?, current: Component)
Expand Down

0 comments on commit c2a62f9

Please sign in to comment.