in facebook-core/src/main/java/com/facebook/appevents/codeless/CodelessMatcher.kt [281:335]
fun findViewByPath(
mapping: EventBinding?,
view: View?,
path: List<PathComponent>,
level: Int,
index: Int,
mapKey: String
): List<MatchedView> {
val mapKey = "$mapKey.$index"
val result: MutableList<MatchedView> = ArrayList()
if (null == view) {
return result
}
if (level >= path.size) {
// Match all children views if their parent view is matched
result.add(MatchedView(view, mapKey))
} else {
val pathElement = path[level]
if (pathElement.className == PARENT_CLASS_NAME) {
val parent = view.parent
if (parent is ViewGroup) {
val visibleViews = findVisibleChildren(parent)
val childCount = visibleViews.size
for (i in 0 until childCount) {
val child = visibleViews[i]
val matchedViews = findViewByPath(mapping, child, path, level + 1, i, mapKey)
result.addAll(matchedViews)
}
}
return result
} else if (pathElement.className == CURRENT_CLASS_NAME) {
// Set self as selected element
result.add(MatchedView(view, mapKey))
return result
}
if (!isTheSameView(view, pathElement, index)) {
return result
}
// Found it!
if (level == path.size - 1) {
result.add(MatchedView(view, mapKey))
}
}
if (view is ViewGroup) {
val visibleViews = findVisibleChildren(view)
val childCount = visibleViews.size
for (i in 0 until childCount) {
val child = visibleViews[i]
val matchedViews = findViewByPath(mapping, child, path, level + 1, i, mapKey)
result.addAll(matchedViews)
}
}
return result
}