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:
committed by
Facebook Github Bot
parent
9e673a07a8
commit
1c5ecce667
@@ -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();
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.facebook.sonar.plugins.inspector.NodeDescriptor;
|
||||
import com.facebook.sonar.plugins.inspector.Touch;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class LithoViewDescriptor extends NodeDescriptor<LithoView> {
|
||||
|
||||
@@ -39,6 +40,12 @@ public class LithoViewDescriptor extends NodeDescriptor<LithoView> {
|
||||
return descriptor.getName(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAXName(LithoView node) throws Exception {
|
||||
final NodeDescriptor descriptor = descriptorForClass(ViewGroup.class);
|
||||
return descriptor.getAXName(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChildCount(LithoView node) {
|
||||
return DebugComponent.getRootInstance(node) == null ? 0 : 1;
|
||||
@@ -49,6 +56,11 @@ public class LithoViewDescriptor extends NodeDescriptor<LithoView> {
|
||||
return DebugComponent.getRootInstance(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Object getAXChildAt(LithoView node, int index) {
|
||||
return DebugComponent.getRootInstance(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Named<SonarObject>> getData(LithoView node) throws Exception {
|
||||
final List<Named<SonarObject>> props = new ArrayList<>();
|
||||
@@ -74,6 +86,14 @@ public class LithoViewDescriptor extends NodeDescriptor<LithoView> {
|
||||
return props;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Named<SonarObject>> getAXData(LithoView node) throws Exception {
|
||||
final List<Named<SonarObject>> props = new ArrayList<>();
|
||||
final NodeDescriptor descriptor = descriptorForClass(ViewGroup.class);
|
||||
props.addAll(descriptor.getAXData(node));
|
||||
return props;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(LithoView node, String[] path, SonarDynamic value) throws Exception {
|
||||
final NodeDescriptor descriptor = descriptorForClass(ViewGroup.class);
|
||||
@@ -86,6 +106,12 @@ public class LithoViewDescriptor extends NodeDescriptor<LithoView> {
|
||||
return descriptor.getAttributes(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Named<String>> getAXAttributes(LithoView node) throws Exception {
|
||||
final NodeDescriptor descriptor = descriptorForClass(ViewGroup.class);
|
||||
return descriptor.getAXAttributes(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHighlighted(LithoView node, boolean selected) throws Exception {
|
||||
final NodeDescriptor descriptor = descriptorForClass(ViewGroup.class);
|
||||
|
||||
Reference in New Issue
Block a user