Sonar tag for skipping empty view groups in layout target mode

Summary:
I think it's somewhat common to have large containers that can hold future views, especially fragments. The problem is the presence of these containers can block the layout inspector's "target" mode.

I found out from cekkaewnumchai that Flipper does in fact return multiple results from the pick, but I think it could still be helpful to have this new tag since it is more convenient than having to do the secondary drill down each time.

Reviewed By: jknoxville

Differential Revision: D22284972

fbshipit-source-id: 1a2826ec746e4f31690db33ed72815ae168bffab
This commit is contained in:
Richard Zadorozny
2020-07-02 08:37:44 -07:00
committed by Facebook GitHub Bot
parent 51e37311d0
commit 91cccbe436
3 changed files with 33 additions and 4 deletions

View File

@@ -294,12 +294,31 @@ public class ViewGroupDescriptor extends NodeDescriptor<ViewGroup> {
}
private static boolean shouldSkip(View view) {
Object tag = view.getTag(R.id.flipper_skip_view_traversal);
if (!(tag instanceof Boolean)) {
return false;
if (hasTag(view, R.id.flipper_skip_view_traversal)) {
return true;
}
return (Boolean) tag;
if (view instanceof ViewGroup
&& hasTag(view, R.id.flipper_skip_empty_view_group_traversal)
&& !hasVisibleChildren((ViewGroup) view)) {
return true;
}
return false;
}
private static boolean hasTag(View view, int id) {
Object tag = view.getTag(id);
return tag instanceof Boolean && (Boolean) tag;
}
private static boolean hasVisibleChildren(ViewGroup viewGroup) {
for (int i = 0; i < viewGroup.getChildCount(); i++) {
if (viewGroup.getChildAt(i).getVisibility() == View.VISIBLE) {
return true;
}
}
return false;
}
@Override

View File

@@ -8,4 +8,5 @@
<resources>
<item type="id" name="flipper_skip_view_traversal"/>
<item type="id" name="flipper_skip_empty_view_group_traversal"/>
</resources>