mirror of
https://github.com/divkit/divkit.git
synced 2026-05-07 20:02:32 +00:00
fix NoSuchElementException at Div2View.trackChildrenVisibility() call
commit_hash:2a5430650096a5d2ac7f8930a35cbe4642ff524b
This commit is contained in:
@@ -87,6 +87,7 @@ import com.yandex.div.internal.core.VariableMutationHandler
|
||||
import com.yandex.div.internal.util.UiThreadHandler.Companion.executeOnMainThreadBlocking
|
||||
import com.yandex.div.internal.util.hasScrollableChildUnder
|
||||
import com.yandex.div.internal.util.immutableCopy
|
||||
import com.yandex.div.internal.util.toMapSafe
|
||||
import com.yandex.div.internal.widget.FrameContainerLayout
|
||||
import com.yandex.div.internal.widget.menu.OverflowMenuSubscriber
|
||||
import com.yandex.div.json.expressions.ExpressionResolver
|
||||
@@ -636,7 +637,7 @@ class Div2View private constructor(
|
||||
fun trackChildrenVisibility(): Unit = bindingDispatcher.runWithinBindingContext {
|
||||
val visibilityActionTracker = div2Component.visibilityActionTracker
|
||||
val bindingsSnapshot = synchronized(viewToDivBindings) {
|
||||
viewToDivBindings.toMap()
|
||||
viewToDivBindings.toMapSafe()
|
||||
}
|
||||
bindingsSnapshot.forEach { (view, div) ->
|
||||
view.bindingContext?.expressionResolver?.let {
|
||||
@@ -652,7 +653,7 @@ class Div2View private constructor(
|
||||
private fun discardChildrenVisibility() {
|
||||
val visibilityActionTracker = div2Component.visibilityActionTracker
|
||||
val bindingsSnapshot = synchronized(viewToDivBindings) {
|
||||
viewToDivBindings.toMap()
|
||||
viewToDivBindings.toMapSafe()
|
||||
}
|
||||
bindingsSnapshot.forEach { (view, div) ->
|
||||
view.bindingContext?.expressionResolver?.let {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.yandex.div.internal.util
|
||||
import androidx.collection.ArrayMap
|
||||
import com.yandex.div.core.annotations.InternalApi
|
||||
import java.util.Collections
|
||||
import java.util.WeakHashMap
|
||||
|
||||
@InternalApi
|
||||
public fun <K, V> arrayMap(): MutableMap<K, V> = ArrayMap<K, V>()
|
||||
@@ -63,3 +64,20 @@ public inline fun <T> List<T>?.compareNullableWith(other: List<T>?, comparator:
|
||||
|
||||
return compareWith(other, comparator)
|
||||
}
|
||||
|
||||
@InternalApi
|
||||
public fun <K, V> WeakHashMap<out K, V>.toMapSafe(): Map<K, V> {
|
||||
if (isEmpty()) {
|
||||
return emptyMap()
|
||||
}
|
||||
|
||||
val result = mutableMapOf<K, V>()
|
||||
val iterator = entries.iterator()
|
||||
try {
|
||||
while (iterator.hasNext()) {
|
||||
val entry = iterator.next()
|
||||
result[entry.key] = entry.value
|
||||
}
|
||||
} catch (e: NoSuchElementException) { }
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user