From 9280b3178dbea7f61241fd41940da143523e1aab Mon Sep 17 00:00:00 2001 From: John Knox Date: Thu, 6 Feb 2020 05:01:57 -0800 Subject: [PATCH] Include positionOnScreen in layout data Summary: Context: https://fb.workplace.com/groups/flippersupport/permalink/804152663398727/ This gives flipper the location of every node, in relation to the entire screen. This allows it to visualize the position of each node on it's own diagram, overlayed over a screenshot for example. The use case in mind is after importing flipper data, you'll still be able to see layout nodes overlayed over a screenshot taken during export. Currently this is only added to Android Views, meaning we don't get it for Litho views or anything on iOS. This is basically to get something working end-to-end, and if it's all good, then I'll add the other types of views. Reviewed By: passy Differential Revision: D19747691 fbshipit-source-id: 8ba3aae6b7685de6faaf55b9628c200802801db4 --- .../plugins/inspector/descriptors/ViewDescriptor.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/facebook/flipper/plugins/inspector/descriptors/ViewDescriptor.java b/android/src/main/java/com/facebook/flipper/plugins/inspector/descriptors/ViewDescriptor.java index af58717ff..b85c02ba6 100644 --- a/android/src/main/java/com/facebook/flipper/plugins/inspector/descriptors/ViewDescriptor.java +++ b/android/src/main/java/com/facebook/flipper/plugins/inspector/descriptors/ViewDescriptor.java @@ -101,6 +101,8 @@ public class ViewDescriptor extends NodeDescriptor { @Override public List> getData(View node) { + final int[] positionOnScreen = new int[2]; + node.getLocationOnScreen(positionOnScreen); final FlipperObject.Builder viewProps = new FlipperObject.Builder() .put("height", InspectorValue.mutable(node.getHeight())) @@ -147,7 +149,13 @@ public class ViewDescriptor extends NodeDescriptor { "pivot", new FlipperObject.Builder() .put("x", InspectorValue.mutable(node.getPivotX())) - .put("y", InspectorValue.mutable(node.getPivotY()))); + .put("y", InspectorValue.mutable(node.getPivotY()))) + .put( + "positionOnScreen", + new FlipperObject.Builder() + .put("x", positionOnScreen[0]) + .put("y", positionOnScreen[1]) + .build()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { viewProps