Include non-drawable litho components in AX tree + small sidebar edit

Summary:
Fixed issue with DebugComponentDescriptors being left out of accessibility tree so the AX tree now includes all Litho view nodes (not Litho accessibility nodes yet). Litho drawables have no accessibility properties so these are not included. Also changed default for getAXChildAt to do whatever the original view tree does for that node and added a getAXChildCount function to better customize the accessibility tree.

Segmented the ax sidebar into properties directly form the view and properties derived from the AccessibilityNodeInfo.

Differential Revision: D8861129

fbshipit-source-id: 987683ef45188aa9cb587cc0e5ffba8fbf40136d
This commit is contained in:
Sara Valderrama
2018-07-16 16:52:47 -07:00
committed by Facebook Github Bot
parent e83c8d31a2
commit 5ceb3e4ffe
5 changed files with 84 additions and 21 deletions

View File

@@ -12,7 +12,6 @@ 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;
@@ -32,7 +31,6 @@ 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;
@@ -126,12 +124,12 @@ public class DebugComponentDescriptor extends NodeDescriptor<DebugComponent> {
}
@Override
public String getAXName(DebugComponent node) {
View v = node.getComponentHost();
AccessibilityNodeInfoCompat nodeInfo = ViewAccessibilityHelper.createNodeInfoFromView(v);
String name = nodeInfo.getClassName().toString();
nodeInfo.recycle();
return name;
public String getAXName(DebugComponent node) throws Exception {
NodeDescriptor componentDescriptor = descriptorForClass(node.getComponent().getClass());
if (componentDescriptor.getClass() != ObjectDescriptor.class) {
return componentDescriptor.getAXName(node.getComponent());
}
return node.getComponent().getSimpleName();
}
@Override
@@ -143,6 +141,15 @@ public class DebugComponentDescriptor extends NodeDescriptor<DebugComponent> {
}
}
@Override
public int getAXChildCount(DebugComponent node) {
if (node.getMountedView() != null) {
return 1;
} else {
return node.getChildComponents().size();
}
}
@Override
public Object getChildAt(DebugComponent node, int index) {
final View mountedView = node.getMountedView();
@@ -158,7 +165,7 @@ public class DebugComponentDescriptor extends NodeDescriptor<DebugComponent> {
}
@Override
public @Nullable Object getAXChildAt(DebugComponent node, int index) {
public Object getAXChildAt(DebugComponent node, int index) {
final View mountedView = node.getMountedView();
if (mountedView != null) {
@@ -201,7 +208,11 @@ public class DebugComponentDescriptor extends NodeDescriptor<DebugComponent> {
}
@Override
public List<Named<SonarObject>> getAXData(DebugComponent node) {
public List<Named<SonarObject>> getAXData(DebugComponent node) throws Exception {
NodeDescriptor componentDescriptor = descriptorForClass(node.getComponent().getClass());
if (componentDescriptor.getClass() != ObjectDescriptor.class) {
return componentDescriptor.getAXData(node.getComponent());
}
final List<Named<SonarObject>> data = new ArrayList<>();
final SonarObject accessibilityData = getAccessibilityData(node);
if (accessibilityData != null) {