NodeInfo tree working (besides litho nodes)

Summary: The second tree has access to all AX NodeInfo properties (they are not in the sidebar yet). Infrastructure set up to customize displayed information bassed on what is most useful. Descriptors for views updated to include AX functionality and non-view descriptors AX functions defaulted to null/empty. Non-view nodes (like Fragments, Window, Appication) no longer included in AX tree. Corresponding nodes will be highlighted (although not expanded) on click in either tree.

Differential Revision: D8795800

fbshipit-source-id: cf2333f69bfecca3ff84aae62681c684dfa14bf3
This commit is contained in:
Sara Valderrama
2018-07-12 09:23:29 -07:00
committed by Facebook Github Bot
parent 9e673a07a8
commit 1c5ecce667
8 changed files with 284 additions and 8 deletions

View File

@@ -12,6 +12,7 @@ import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.support.v4.util.Pair;
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
import android.view.View;
import com.facebook.litho.Component;
import com.facebook.litho.ComponentContext;
@@ -31,6 +32,7 @@ import com.facebook.sonar.plugins.inspector.NodeDescriptor;
import com.facebook.sonar.plugins.inspector.Touch;
import com.facebook.sonar.plugins.inspector.descriptors.ObjectDescriptor;
import com.facebook.sonar.plugins.inspector.descriptors.utils.AccessibilityUtil;
import com.facebook.sonar.plugins.inspector.descriptors.utils.ViewAccessibilityHelper;
import com.facebook.yoga.YogaAlign;
import com.facebook.yoga.YogaDirection;
import com.facebook.yoga.YogaEdge;
@@ -41,6 +43,7 @@ import com.facebook.yoga.YogaValue;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -122,6 +125,15 @@ public class DebugComponentDescriptor extends NodeDescriptor<DebugComponent> {
return node.getComponent().getSimpleName();
}
@Override
public String getAXName(DebugComponent node) {
View v = node.getComponentHost();
AccessibilityNodeInfoCompat nodeInfo = ViewAccessibilityHelper.createNodeInfoFromView(v);
String name = nodeInfo.getClassName().toString();
nodeInfo.recycle();
return name;
}
@Override
public int getChildCount(DebugComponent node) {
if (node.getMountedView() != null || node.getMountedDrawable() != null) {
@@ -145,6 +157,17 @@ public class DebugComponentDescriptor extends NodeDescriptor<DebugComponent> {
}
}
@Override
public @Nullable Object getAXChildAt(DebugComponent node, int index) {
final View mountedView = node.getMountedView();
if (mountedView != null) {
return mountedView;
} else {
return node.getChildComponents().get(index);
}
}
@Override
public List<Named<SonarObject>> getData(DebugComponent node) throws Exception {
NodeDescriptor componentDescriptor = descriptorForClass(node.getComponent().getClass());
@@ -177,6 +200,16 @@ public class DebugComponentDescriptor extends NodeDescriptor<DebugComponent> {
return data;
}
@Override
public List<Named<SonarObject>> getAXData(DebugComponent node) {
final List<Named<SonarObject>> data = new ArrayList<>();
final SonarObject accessibilityData = getAccessibilityData(node);
if (accessibilityData != null) {
data.add(new Named<>("Accessibility", accessibilityData));
}
return data;
}
@Nullable
private static SonarObject getLayoutData(DebugComponent node) {
final DebugLayoutNode layout = node.getLayoutNode();
@@ -457,6 +490,11 @@ public class DebugComponentDescriptor extends NodeDescriptor<DebugComponent> {
return attributes;
}
@Override
public List<Named<String>> getAXAttributes(DebugComponent node) {
return Collections.EMPTY_LIST;
}
@Override
public void setHighlighted(DebugComponent node, boolean selected) {
final LithoView lithoView = node.getLithoView();