From e86a5166ad7395348cc703af4bc8a987fcf0c7fc Mon Sep 17 00:00:00 2001 From: Mihaela Ogrezeanu Date: Tue, 12 Feb 2019 06:25:12 -0800 Subject: [PATCH] Add descriptors to view a Section as a child of LithoRecyclerView Summary: This doesn't add new behaviour. It adds NodeDescriptor implementations for rendering Section nodes inside Litho flipper inspector. We'll consider LithoRecyclerView as the point where we can detect a section hierarchy, and it will (for now) have as a child a DebugSection which is the root of the SectionHierarchy. Depends on D13802978 Reviewed By: astreet Differential Revision: D13803272 fbshipit-source-id: a5367d97315349770201a29f5d5bd05baec0405e --- .../plugins/litho/DebugSectionDescriptor.java | 85 +++++++++++ .../litho/LithoRecyclerViewDescriptor.java | 132 ++++++++++++++++++ 2 files changed, 217 insertions(+) create mode 100644 android/src/main/java/com/facebook/flipper/plugins/litho/DebugSectionDescriptor.java create mode 100644 android/src/main/java/com/facebook/flipper/plugins/litho/LithoRecyclerViewDescriptor.java 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 new file mode 100644 index 000000000..f20f90ae8 --- /dev/null +++ b/android/src/main/java/com/facebook/flipper/plugins/litho/DebugSectionDescriptor.java @@ -0,0 +1,85 @@ +/** + * Copyright (c) Facebook, Inc. and its 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.litho; + +import com.facebook.flipper.core.FlipperDynamic; +import com.facebook.flipper.core.FlipperObject; +import com.facebook.flipper.plugins.inspector.Named; +import com.facebook.flipper.plugins.inspector.NodeDescriptor; +import com.facebook.flipper.plugins.inspector.Touch; +import com.facebook.litho.sections.debug.DebugSection; +import java.util.List; + +public class DebugSectionDescriptor extends NodeDescriptor { + @Override + public void init(DebugSection node) throws Exception {} + + @Override + public String getId(DebugSection node) throws Exception { + return node.getGlobalKey(); + } + + @Override + public String getName(DebugSection node) throws Exception { + return node.getName(); + } + + @Override + public int getChildCount(DebugSection node) throws Exception { + return node.getSectionChildren().size(); + } + + @Override + public Object getChildAt(DebugSection node, int index) throws Exception { + return node.getSectionChildren().get(index); + } + + @Override + public List> getData(DebugSection node) throws Exception { + // TODO T39526148 add changeset info + return null; + } + + @Override + public void setValue(DebugSection node, String[] path, FlipperDynamic value) throws Exception { + // TODO T39526148 + } + + @Override + public List> getAttributes(DebugSection node) throws Exception { + // TODO T39526148 + return null; + } + + @Override + public void setHighlighted(DebugSection node, boolean selected, boolean isAlignmentMode) + throws Exception { + // TODO T39526148 + } + + @Override + public void hitTest(DebugSection node, Touch touch) throws Exception { + // TODO T39526148 + } + + @Override + public String getDecoration(DebugSection node) throws Exception { + // TODO T39526148 + return null; + } + + @Override + public boolean matches(String query, DebugSection node) throws Exception { + // TODO T39526148 + return false; + } + + @Override + public int getAXChildCount(DebugSection node) { + return 0; + } +} diff --git a/android/src/main/java/com/facebook/flipper/plugins/litho/LithoRecyclerViewDescriptor.java b/android/src/main/java/com/facebook/flipper/plugins/litho/LithoRecyclerViewDescriptor.java new file mode 100644 index 000000000..5377ed691 --- /dev/null +++ b/android/src/main/java/com/facebook/flipper/plugins/litho/LithoRecyclerViewDescriptor.java @@ -0,0 +1,132 @@ +/** + * Copyright (c) Facebook, Inc. and its 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.litho; + +import android.view.View; +import android.view.ViewGroup; +import com.facebook.flipper.core.FlipperDynamic; +import com.facebook.flipper.core.FlipperObject; +import com.facebook.flipper.plugins.inspector.Named; +import com.facebook.flipper.plugins.inspector.NodeDescriptor; +import com.facebook.flipper.plugins.inspector.Touch; +import com.facebook.litho.sections.debug.DebugSection; +import com.facebook.litho.widget.LithoRecylerView; +import java.util.ArrayList; +import java.util.List; + +public class LithoRecyclerViewDescriptor extends NodeDescriptor { + @Override + public void init(LithoRecylerView node) throws Exception {} + + @Override + public String getId(LithoRecylerView node) throws Exception { + final NodeDescriptor descriptor = descriptorForClass(ViewGroup.class); + return descriptor.getId(node); + } + + @Override + public String getName(LithoRecylerView node) throws Exception { + final NodeDescriptor descriptor = descriptorForClass(ViewGroup.class); + return descriptor.getName(node); + } + + @Override + public int getChildCount(LithoRecylerView node) throws Exception { + // TODO T39526148 this might not always be true when using the RecyclerBinder manually. + return 1; + } + + @Override + public Object getChildAt(LithoRecylerView node, int index) throws Exception { + // TODO T39526148 account for the case above + final NodeDescriptor descriptor = descriptorForClass(ViewGroup.class); + int count = descriptor.getChildCount(node); + + final List childrenViews = new ArrayList<>(); + for (int i = 0; i < count; i++) { + childrenViews.add((View) descriptor.getChildAt(node, i)); + } + + return DebugSection.getRootInstance(childrenViews); + } + + @Override + public List> getData(LithoRecylerView node) throws Exception { + final List> props = new ArrayList<>(); + final NodeDescriptor descriptor = descriptorForClass(ViewGroup.class); + props.addAll(descriptor.getData(node)); + + return props; + } + + @Override + public void setValue(LithoRecylerView node, String[] path, FlipperDynamic value) + throws Exception { + final NodeDescriptor descriptor = descriptorForClass(ViewGroup.class); + descriptor.setValue(node, path, value); + } + + @Override + public List> getAttributes(LithoRecylerView node) throws Exception { + final NodeDescriptor descriptor = descriptorForClass(ViewGroup.class); + return descriptor.getAttributes(node); + } + + @Override + public FlipperObject getExtraInfo(LithoRecylerView node) { + final NodeDescriptor descriptor = descriptorForClass(ViewGroup.class); + return descriptor.getExtraInfo(node); + } + + @Override + public void hitTest(LithoRecylerView node, Touch touch) throws Exception { + touch.continueWithOffset(0, 0, 0); + } + + @Override + public void axHitTest(LithoRecylerView node, Touch touch) throws Exception { + final NodeDescriptor descriptor = descriptorForClass(ViewGroup.class); + descriptor.axHitTest(node, touch); + } + + @Override + public String getAXName(LithoRecylerView node) throws Exception { + final NodeDescriptor descriptor = descriptorForClass(ViewGroup.class); + return descriptor.getAXName(node); + } + + @Override + public List> getAXAttributes(LithoRecylerView node) throws Exception { + final NodeDescriptor descriptor = descriptorForClass(ViewGroup.class); + return descriptor.getAXAttributes(node); + } + + @Override + public void setHighlighted(LithoRecylerView node, boolean selected, boolean isAlignmentMode) + throws Exception { + final NodeDescriptor descriptor = descriptorForClass(ViewGroup.class); + descriptor.setHighlighted(node, selected, isAlignmentMode); + } + + @Override + public String getDecoration(LithoRecylerView node) throws Exception { + final NodeDescriptor descriptor = descriptorForClass(ViewGroup.class); + return descriptor.getDecoration(node); + } + + @Override + public String getAXDecoration(LithoRecylerView node) throws Exception { + final NodeDescriptor descriptor = descriptorForClass(ViewGroup.class); + return descriptor.getAXDecoration(node); + } + + @Override + public boolean matches(String query, LithoRecylerView node) throws Exception { + NodeDescriptor descriptor = descriptorForClass(Object.class); + return descriptor.matches(query, node); + } +}