mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-09 09:30:10 +08:00
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:
@@ -11,6 +11,7 @@ package com.facebook.react.flat;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.facebook.csslayout.CSSNode;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.uimanager.LayoutShadowNode;
|
||||
import com.facebook.react.uimanager.OnLayoutEvent;
|
||||
@@ -55,6 +56,7 @@ import com.facebook.react.views.view.ReactClippingViewGroupHelper;
|
||||
private @Nullable DrawBackgroundColor mDrawBackground;
|
||||
private boolean mClipToBounds = false;
|
||||
private boolean mIsUpdated = true;
|
||||
private boolean mForceMountChildrenToView;
|
||||
private float mClipLeft;
|
||||
private float mClipTop;
|
||||
private float mClipRight;
|
||||
@@ -89,6 +91,20 @@ import com.facebook.react.views.view.ReactClippingViewGroupHelper;
|
||||
}
|
||||
}
|
||||
|
||||
/* package */ final void forceMountChildrenToView() {
|
||||
if (mForceMountChildrenToView) {
|
||||
return;
|
||||
}
|
||||
|
||||
mForceMountChildrenToView = true;
|
||||
for (int i = 0, childCount = getChildCount(); i != childCount; ++i) {
|
||||
ReactShadowNode child = getChildAt(i);
|
||||
if (child instanceof FlatShadowNode) {
|
||||
((FlatShadowNode) child).forceMountToView();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects DrawCommands produced by this FlatShadowNode.
|
||||
*/
|
||||
@@ -157,6 +173,14 @@ import com.facebook.react.views.view.ReactClippingViewGroupHelper;
|
||||
return mViewBottom - mViewTop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addChildAt(CSSNode child, int i) {
|
||||
super.addChildAt(child, i);
|
||||
if (mForceMountChildrenToView && child instanceof FlatShadowNode) {
|
||||
((FlatShadowNode) child).forceMountToView();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks root node as updated to trigger a StateBuilder pass to collect DrawCommands for the node
|
||||
* tree. Use it when FlatShadowNode is updated but doesn't require a layout pass (e.g. background
|
||||
|
||||
Reference in New Issue
Block a user