Summary: Switches the tree to use the view hierarchy for Litho nodes rather than Litho component hierarchy since Accessibility services interact with the views rendered. Includes a few more properties in the accessibility sidebar and updates to the segmented sidebar based on derived/non-derived properties for all views. Also adds functions to the AccessibilityUtil to be able to work on the accessibility sidebar while still leaving the non-accessibility sidebar unchanged. Eventually the accessibility panel will be removed from 'normal' mode and the original functions will no longer be necessary. Reviewed By: blavalla Differential Revision: D8881739 fbshipit-source-id: 9ce37e8f18025538cba2c86c0895ee38d13d024b
143 lines
4.4 KiB
Java
143 lines
4.4 KiB
Java
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
package com.facebook.litho.sonar;
|
|
|
|
import android.graphics.Rect;
|
|
import android.view.ViewGroup;
|
|
import com.facebook.litho.DebugComponent;
|
|
import com.facebook.litho.LithoView;
|
|
import com.facebook.sonar.core.SonarDynamic;
|
|
import com.facebook.sonar.core.SonarObject;
|
|
import com.facebook.sonar.plugins.inspector.Named;
|
|
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> {
|
|
|
|
@Override
|
|
public void init(LithoView node) throws Exception {
|
|
node.setOnDirtyMountListener(
|
|
new LithoView.OnDirtyMountListener() {
|
|
@Override
|
|
public void onDirtyMount(LithoView view) {
|
|
invalidate(view);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public String getId(LithoView node) throws Exception {
|
|
final NodeDescriptor descriptor = descriptorForClass(ViewGroup.class);
|
|
return descriptor.getId(node);
|
|
}
|
|
|
|
@Override
|
|
public String getName(LithoView node) throws Exception {
|
|
final NodeDescriptor descriptor = descriptorForClass(ViewGroup.class);
|
|
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;
|
|
}
|
|
|
|
@Override
|
|
public int getAXChildCount(LithoView node) {
|
|
return node.getChildCount();
|
|
}
|
|
|
|
@Override
|
|
public Object getChildAt(LithoView node, int index) {
|
|
return DebugComponent.getRootInstance(node);
|
|
}
|
|
|
|
@Override
|
|
public @Nullable Object getAXChildAt(LithoView node, int index) {
|
|
return node.getChildAt(index);
|
|
}
|
|
|
|
@Override
|
|
public List<Named<SonarObject>> getData(LithoView node) throws Exception {
|
|
final List<Named<SonarObject>> props = new ArrayList<>();
|
|
final NodeDescriptor descriptor = descriptorForClass(ViewGroup.class);
|
|
final Rect mountedBounds = node.getPreviousMountBounds();
|
|
|
|
props.add(
|
|
0,
|
|
new Named<>(
|
|
"LithoView",
|
|
new SonarObject.Builder()
|
|
.put(
|
|
"mountbounds",
|
|
new SonarObject.Builder()
|
|
.put("left", mountedBounds.left)
|
|
.put("top", mountedBounds.top)
|
|
.put("right", mountedBounds.right)
|
|
.put("bottom", mountedBounds.bottom))
|
|
.build()));
|
|
|
|
props.addAll(descriptor.getData(node));
|
|
|
|
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);
|
|
descriptor.setValue(node, path, value);
|
|
}
|
|
|
|
@Override
|
|
public List<Named<String>> getAttributes(LithoView node) throws Exception {
|
|
final NodeDescriptor descriptor = descriptorForClass(ViewGroup.class);
|
|
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);
|
|
descriptor.setHighlighted(node, selected);
|
|
}
|
|
|
|
@Override
|
|
public void hitTest(LithoView node, Touch touch) {
|
|
touch.continueWithOffset(0, 0, 0);
|
|
}
|
|
|
|
@Override
|
|
public String getDecoration(LithoView node) throws Exception {
|
|
final NodeDescriptor descriptor = descriptorForClass(ViewGroup.class);
|
|
return descriptor.getDecoration(node);
|
|
}
|
|
|
|
@Override
|
|
public boolean matches(String query, LithoView node) throws Exception {
|
|
NodeDescriptor descriptor = descriptorForClass(Object.class);
|
|
return descriptor.matches(query, node);
|
|
}
|
|
}
|