Change hit test to explore all nodes
Summary: Previously we would only consider a node hit if the nouse pos was inside every parents. There are a few reason why this isnt ideal: 1. Fragments are return 0 bounds 2. Many hierachys (particually in litho ) have nonsensical strucutres where your parent may have hieght 0, or children overflow parents bounds. Therefore it was impossible to select many nodes but unclear why Reviewed By: lblasa Differential Revision: D41304499 fbshipit-source-id: d75c8060f71fa0b972f136cb11258b62a9c98ebc
This commit is contained in:
committed by
Facebook GitHub Bot
parent
53c15b2e59
commit
1d920efe10
@@ -301,27 +301,26 @@ function hitTest(node: NestedNode, mouseCoordinate: Coordinate): NestedNode[] {
|
||||
function hitTestRec(node: NestedNode, mouseCoordinate: Coordinate): boolean {
|
||||
const nodeBounds = node.bounds;
|
||||
|
||||
if (boundsContainsCoordinate(nodeBounds, mouseCoordinate)) {
|
||||
let children = node.children;
|
||||
const thisNodeHit = boundsContainsCoordinate(nodeBounds, mouseCoordinate);
|
||||
|
||||
if (node.activeChildIdx != null) {
|
||||
children = [node.children[node.activeChildIdx]];
|
||||
}
|
||||
const offsetMouseCoord = offsetCoordinate(mouseCoordinate, nodeBounds);
|
||||
let childHit = false;
|
||||
let children = node.children;
|
||||
|
||||
for (const child of children) {
|
||||
childHit = hitTestRec(child, offsetMouseCoord) || childHit;
|
||||
}
|
||||
if (node.activeChildIdx != null) {
|
||||
children = [node.children[node.activeChildIdx]];
|
||||
}
|
||||
const offsetMouseCoord = offsetCoordinate(mouseCoordinate, nodeBounds);
|
||||
let childHit = false;
|
||||
|
||||
if (!childHit) {
|
||||
res.push(node);
|
||||
}
|
||||
|
||||
return true;
|
||||
for (const child of children) {
|
||||
childHit = hitTestRec(child, offsetMouseCoord) || childHit;
|
||||
}
|
||||
|
||||
return false;
|
||||
const hit = thisNodeHit && !childHit;
|
||||
if (hit) {
|
||||
res.push(node);
|
||||
}
|
||||
|
||||
return hit;
|
||||
}
|
||||
|
||||
hitTestRec(node, mouseCoordinate);
|
||||
|
||||
Reference in New Issue
Block a user