Skip to content

Commit

Permalink
Same for view group holder.
Browse files Browse the repository at this point in the history
  • Loading branch information
sdelaysam committed May 4, 2021
1 parent f934025 commit af8ea63
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import androidx.annotation.CallSuper
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.cancelChildren
import org.sdelaysam.configurator.RequiresCoroutineScope
import org.sdelaysam.configurator.adapter.AdapterEntry

Expand All @@ -21,9 +21,11 @@ abstract class BasicViewHolder(val view: View) {

@CallSuper
open fun onBind(data: AdapterEntry) {
coroutineScope?.cancel()
coroutineScope?.coroutineContext?.cancelChildren()
if (data is RequiresCoroutineScope) {
coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
if (coroutineScope == null) {
coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
}
data.setCoroutineScope(coroutineScope!!)
} else {
coroutineScope = null
Expand All @@ -32,8 +34,7 @@ abstract class BasicViewHolder(val view: View) {

@CallSuper
open fun onRecycled() {
coroutineScope?.cancel()
coroutineScope = null
coroutineScope?.coroutineContext?.cancelChildren()
}

interface Factory {
Expand Down

0 comments on commit af8ea63

Please # to comment.