From af8ea63d9e7acdb795ec13e6581a5f2c2666b42b Mon Sep 17 00:00:00 2001 From: Sergey Petrov Date: Tue, 4 May 2021 11:53:40 +0700 Subject: [PATCH] Same for view group holder. --- .../configurator/viewgroup/BasicViewHolder.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/adapter-viewgroup/src/main/java/org/sdelaysam/configurator/viewgroup/BasicViewHolder.kt b/adapter-viewgroup/src/main/java/org/sdelaysam/configurator/viewgroup/BasicViewHolder.kt index b178021..a196dad 100644 --- a/adapter-viewgroup/src/main/java/org/sdelaysam/configurator/viewgroup/BasicViewHolder.kt +++ b/adapter-viewgroup/src/main/java/org/sdelaysam/configurator/viewgroup/BasicViewHolder.kt @@ -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 @@ -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 @@ -32,8 +34,7 @@ abstract class BasicViewHolder(val view: View) { @CallSuper open fun onRecycled() { - coroutineScope?.cancel() - coroutineScope = null + coroutineScope?.coroutineContext?.cancelChildren() } interface Factory {