Skip to content

Commit

Permalink
Use z-sorted traverse in InteropContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
MatkovIvan committed May 3, 2024
1 parent 5cd70c9 commit f945ee3
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ package androidx.compose.ui.node

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.areObjectsOfSameType
import androidx.compose.ui.layout.OverlayLayout
import androidx.compose.ui.node.TraversableNode.Companion.TraverseDescendantsAction.CancelTraversal
import androidx.compose.ui.node.TraversableNode.Companion.TraverseDescendantsAction.ContinueTraversal

/**
* An interface for container that controls interop views/components.
Expand All @@ -43,17 +42,19 @@ internal interface InteropContainer<T> {
*/
internal fun <T> InteropContainer<T>.countInteropComponentsBefore(nativeView: T): Int {
var componentsBefore = 0
rootModifier?.traverseDescendants {
if (it.nativeView != nativeView) {
rootModifier?.visitSubtreeIf(Nodes.Traversable, zOrder = true) {
if (TRAVERSAL_NODE_KEY == it.traverseKey && areObjectsOfSameType(this, it)) {
@Suppress("UNCHECKED_CAST")
val interopModifierNode = it as TrackInteropModifierNode<T>
if (interopModifierNode.nativeView == nativeView) return componentsBefore

// It might be inside Compose tree before adding in InteropContainer in case
// if it was initiated out of scroll visible bounds for example.
if (it.nativeView in interopViews) {
componentsBefore++
}
ContinueTraversal
} else {
CancelTraversal
}
true
}
return componentsBefore
}
Expand Down

0 comments on commit f945ee3

Please sign in to comment.