Promote grandchildren of certain views are Views

Summary:
As an optimization, for something like a ScrollView which contains
a FlatViewGroup containing posts, make sure that each post is explicitly
mounted to a View. This may help improve performance, especially when said
Views are otherwise inlined as DrawCommands instead of actual Views.

Reviewed By: astreet

Differential Revision: D3161232
This commit is contained in:
Ahmed El-Helw
2016-06-02 14:02:50 -07:00
parent 0adc390a19
commit 4bb33f93cd
2 changed files with 29 additions and 2 deletions

View File

@@ -23,6 +23,7 @@ import com.facebook.react.uimanager.ViewManager;
@Nullable private final ReactShadowNode mReactShadowNode;
private final boolean mNeedsCustomLayoutForChildren;
private boolean mPaddingChanged = false;
private boolean mForceMountGrandChildrenToView;
/* package */ NativeViewWrapper(ViewManager viewManager) {
ReactShadowNode reactShadowNode = viewManager.createShadowNodeInstance();
@@ -36,11 +37,13 @@ import com.facebook.react.uimanager.ViewManager;
if (viewManager instanceof ViewGroupManager) {
ViewGroupManager viewGroupManager = (ViewGroupManager) viewManager;
mNeedsCustomLayoutForChildren = viewGroupManager.needsCustomLayoutForChildren();
mForceMountGrandChildrenToView = viewGroupManager.shouldPromoteGrandchildren();
} else {
mNeedsCustomLayoutForChildren = false;
}
forceMountToView();
forceMountChildrenToView();
}
@Override
@@ -82,8 +85,8 @@ import com.facebook.react.uimanager.ViewManager;
@Override
public void addChildAt(CSSNode child, int i) {
super.addChildAt(child, i);
if (child instanceof FlatShadowNode) {
((FlatShadowNode) child).forceMountToView();
if (mForceMountGrandChildrenToView && child instanceof FlatShadowNode) {
((FlatShadowNode) child).forceMountChildrenToView();
}
}