Fix active child
Summary: The active child was only being passed for the native scan full traversal, Now we have it for the partial traversal also Reviewed By: lblasa Differential Revision: D39466933 fbshipit-source-id: a0e281e4f9a21bf2edd12f18ecdb68a29ead3476
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0562178739
commit
a0ee774159
@@ -132,6 +132,11 @@ fun Any.identityHashCode(): HashCode {
|
|||||||
return System.identityHashCode(this)
|
return System.identityHashCode(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will traverse the layout hierarchy untill it sees a node that has an observer registered for
|
||||||
|
* it. The first item in the pair is the visited nodes The second item are any observable roots
|
||||||
|
* discovered
|
||||||
|
*/
|
||||||
class PartialLayoutTraversal(
|
class PartialLayoutTraversal(
|
||||||
private val descriptorRegister: DescriptorRegister,
|
private val descriptorRegister: DescriptorRegister,
|
||||||
private val treeObserverfactory: TreeObserverFactory,
|
private val treeObserverfactory: TreeObserverFactory,
|
||||||
@@ -142,7 +147,7 @@ class PartialLayoutTraversal(
|
|||||||
fun traverse(root: Any): Pair<MutableList<Node>, List<Any>> {
|
fun traverse(root: Any): Pair<MutableList<Node>, List<Any>> {
|
||||||
|
|
||||||
val visited = mutableListOf<Node>()
|
val visited = mutableListOf<Node>()
|
||||||
val skipped = mutableListOf<Any>()
|
val observableRoots = mutableListOf<Any>()
|
||||||
val stack = mutableListOf<Any>()
|
val stack = mutableListOf<Any>()
|
||||||
stack.add(root)
|
stack.add(root)
|
||||||
|
|
||||||
@@ -154,7 +159,7 @@ class PartialLayoutTraversal(
|
|||||||
|
|
||||||
// if we encounter a node that has it own observer, dont traverse
|
// if we encounter a node that has it own observer, dont traverse
|
||||||
if (node != root && treeObserverfactory.hasObserverFor(node)) {
|
if (node != root && treeObserverfactory.hasObserverFor(node)) {
|
||||||
skipped.add(node)
|
observableRoots.add(node)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,26 +169,42 @@ class PartialLayoutTraversal(
|
|||||||
descriptor.getChildren(node, children)
|
descriptor.getChildren(node, children)
|
||||||
|
|
||||||
val childrenIds = mutableListOf<String>()
|
val childrenIds = mutableListOf<String>()
|
||||||
|
val activeChild = descriptor.getActiveChild(node)
|
||||||
|
|
||||||
for (child in children) {
|
for (child in children) {
|
||||||
// it might make sense one day to remove id from the descriptor since its always the
|
// it might make sense one day to remove id from the descriptor since its always the
|
||||||
// hash code
|
// hash code
|
||||||
val childDescriptor =
|
val childDescriptor =
|
||||||
descriptorRegister.descriptorForClassUnsafe(child::class.java).asAny()
|
descriptorRegister.descriptorForClassUnsafe(child::class.java).asAny()
|
||||||
childrenIds.add(childDescriptor.getId(child))
|
childrenIds.add(childDescriptor.getId(child))
|
||||||
|
// if there is an active child then dont traverse it
|
||||||
|
if (activeChild == null) {
|
||||||
stack.add(child)
|
stack.add(child)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
var activeChildId: String? = null
|
||||||
|
if (activeChild != null) {
|
||||||
|
stack.add(activeChild)
|
||||||
|
activeChildId =
|
||||||
|
descriptorRegister.descriptorForClassUnsafe(activeChild.javaClass).getId(activeChild)
|
||||||
|
}
|
||||||
|
|
||||||
val attributes = mutableMapOf<String, InspectableObject>()
|
val attributes = mutableMapOf<String, InspectableObject>()
|
||||||
descriptor.getData(node, attributes)
|
descriptor.getData(node, attributes)
|
||||||
|
|
||||||
// NOTE active child null here
|
// NOTE active child null here
|
||||||
visited.add(
|
visited.add(
|
||||||
Node(descriptor.getId(node), descriptor.getName(node), attributes, childrenIds, null))
|
Node(
|
||||||
|
descriptor.getId(node),
|
||||||
|
descriptor.getName(node),
|
||||||
|
attributes,
|
||||||
|
childrenIds,
|
||||||
|
activeChildId))
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
Log.e(LogTag, "Error while processing node ${node.javaClass.name} ${node} ", exception)
|
Log.e(LogTag, "Error while processing node ${node.javaClass.name} ${node} ", exception)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Pair(visited, skipped)
|
return Pair(visited, observableRoots)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user