Traversal tidy up
Summary: This change tidies up the traversal and removes unused LayoutVisitor Reviewed By: LukeDefeo Differential Revision: D39575241 fbshipit-source-id: 2ab101f74ae7b2c16ddf7016abc78a03590916b0
This commit is contained in:
committed by
Facebook GitHub Bot
parent
1fac19facc
commit
bba1275377
@@ -29,25 +29,21 @@ class LayoutTraversal(
|
||||
stack.add(this.root)
|
||||
|
||||
while (stack.isNotEmpty()) {
|
||||
|
||||
val node = stack.removeLast()
|
||||
|
||||
try {
|
||||
|
||||
val descriptor = descriptorRegister.descriptorForClassUnsafe(node::class.java).asAny()
|
||||
|
||||
val children = descriptor.getChildren(node)
|
||||
val activeChild = descriptor.getActiveChild(node)
|
||||
|
||||
val childrenIds = mutableListOf<String>()
|
||||
|
||||
val activeChild = descriptor.getActiveChild(node)
|
||||
for (child in children) {
|
||||
// it might make sense one day to remove id from the descriptor since its always the
|
||||
// hash code
|
||||
children.forEach { child ->
|
||||
val childDescriptor =
|
||||
descriptorRegister.descriptorForClassUnsafe(child::class.java).asAny()
|
||||
// It might make sense one day to remove id from the descriptor since its always the
|
||||
// hash code
|
||||
childrenIds.add(childDescriptor.getId(child))
|
||||
// if there is an active child then don't traverse it
|
||||
// If there is an active child then don't traverse it
|
||||
if (activeChild == null) {
|
||||
stack.add(child)
|
||||
}
|
||||
@@ -61,7 +57,6 @@ class LayoutTraversal(
|
||||
}
|
||||
|
||||
val attributes = descriptor.getData(node)
|
||||
|
||||
result.add(
|
||||
Node(
|
||||
descriptor.getId(node),
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.flipper.plugins.uidebugger.core
|
||||
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
||||
/** Layout Visitor traverses the entire view hierarchy from a given root. */
|
||||
class LayoutVisitor(private val visitor: Visitor) {
|
||||
interface Visitor {
|
||||
fun visit(view: View)
|
||||
}
|
||||
|
||||
fun traverse(view: View) {
|
||||
visitor.visit(view)
|
||||
|
||||
if (view is ViewGroup) {
|
||||
val viewGroup = view as ViewGroup
|
||||
val childCount = viewGroup.childCount - 1
|
||||
for (i in 0 until childCount) {
|
||||
val child = viewGroup.getChildAt(i)
|
||||
traverse(child)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun create(visitor: Visitor): LayoutVisitor {
|
||||
return LayoutVisitor(visitor)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user