From 73b816de162a9d91b8dc74ecd40e0a2f9426a2de Mon Sep 17 00:00:00 2001 From: Mihaela Ogrezeanu Date: Tue, 12 Feb 2019 06:25:13 -0800 Subject: [PATCH] Click to focus in hierarchy Summary: as title; this shouldn't change how focus worked before on views, but accounts for the new Section nodes Depends on D13900789 Reviewed By: astreet Differential Revision: D13900846 fbshipit-source-id: 093016c17b5c1351108dbd9c884bf99a1b4d49cb --- .../plugins/litho/DebugSectionDescriptor.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/facebook/flipper/plugins/litho/DebugSectionDescriptor.java b/android/src/main/java/com/facebook/flipper/plugins/litho/DebugSectionDescriptor.java index b8acb781e..04256eb45 100644 --- a/android/src/main/java/com/facebook/flipper/plugins/litho/DebugSectionDescriptor.java +++ b/android/src/main/java/com/facebook/flipper/plugins/litho/DebugSectionDescriptor.java @@ -121,7 +121,38 @@ public class DebugSectionDescriptor extends NodeDescriptor { @Override public void hitTest(DebugSection node, Touch touch) throws Exception { - // TODO T39526148 + final int childCount = getChildCount(node); + + // For a DiffSectionSpec, check if child view to see if the touch is in its bounds. + // For a GroupSectionSpec, check the bounds of the entire section. + + if (node.isDiffSectionSpec()) { + for (int i = 0; i < childCount; i++) { + View child = (View) getChildAt(node, i); + int left = child.getLeft() + (int) child.getTranslationX(); + int top = (child.getTop() + (int) child.getTranslationY()); + int right = (child.getRight() + (int) child.getTranslationX()); + int bottom = (child.getBottom() + (int) child.getTranslationY()); + + final boolean hit = touch.containedIn(left, top, right, bottom); + if (hit) { + touch.continueWithOffset(i, left, top); + return; + } + } + touch.finish(); + } else { + for (int i = 0; i < childCount; i++) { + DebugSection child = (DebugSection) getChildAt(node, i); + Rect bounds = child.getBounds(); + final boolean hit = touch.containedIn(bounds.left, bounds.top, bounds.right, bounds.bottom); + if (hit) { + touch.continueWithOffset(i, 0, 0); + return; + } + } + touch.finish(); + } } @Override