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
This commit is contained in:
Mihaela Ogrezeanu
2019-02-12 06:25:12 -08:00
committed by Facebook Github Bot
parent 825bfffd21
commit e86a5166ad
2 changed files with 217 additions and 0 deletions

View File

@@ -0,0 +1,85 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* <p>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<DebugSection> {
@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<Named<FlipperObject>> 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<Named<String>> 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;
}
}

View File

@@ -0,0 +1,132 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* <p>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<LithoRecylerView> {
@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<View> childrenViews = new ArrayList<>();
for (int i = 0; i < count; i++) {
childrenViews.add((View) descriptor.getChildAt(node, i));
}
return DebugSection.getRootInstance(childrenViews);
}
@Override
public List<Named<FlipperObject>> getData(LithoRecylerView node) throws Exception {
final List<Named<FlipperObject>> 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<Named<String>> 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<Named<String>> 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);
}
}