Skip to content

Commit

Permalink
create ComponentAdapter.onComponentsUpdated, which will invoke a
Browse files Browse the repository at this point in the history
lambda set by the client (if not-null) immediately after the adapter has
updated the components
  • Loading branch information
flopshot committed Apr 2, 2020
1 parent 2d94b04 commit 68c5d84
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions library/src/main/java/com/seannajera/dkouple/ComponentAdapter.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("unused")

package com.seannajera.dkouple

import android.view.LayoutInflater
Expand All @@ -10,6 +12,8 @@ class ComponentAdapter(private val componentFactory: ComponentFactory) :

private val componentLayouts: ArrayList<Int> = arrayListOf()

private var actionWhenComponentsUpdate: ((List<Component>, List<Component>) -> Unit)? = null

override fun onCreateViewHolder(parent: ViewGroup, layoutId: Int): ComponentView<*> {
val view = LayoutInflater.from(parent.context)
.inflate(layoutId, parent, false)
Expand Down Expand Up @@ -45,6 +49,14 @@ class ComponentAdapter(private val componentFactory: ComponentFactory) :
currentList.forEach {
componentLayouts.add(it::class.annotations.filterIsInstance<DKoupleComponent>().first().layoutId)
}

actionWhenComponentsUpdate?.invoke(previousComponent, currentComponent)
}

fun onComponentsUpdated(
actionWhenComponentsUpdate: ((List<Component>, List<Component>) -> Unit)?
) {
this.actionWhenComponentsUpdate = actionWhenComponentsUpdate
}

fun applyComponents(components: List<Component>) = submitList(components)
Expand Down

0 comments on commit 68c5d84

Please sign in to comment.