mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-10 09:12:46 +08:00
View recycling in JS.
Summary: public Native view recycling implementation based on limited pools of views. In this diff I introduced new UIManager method: dropViews. Instead of removing views from tag->view maps when they are detached we keep them there until we get a call to dropViews with the appropriate tag. JS may keep a pool of object and selectively decide not to enqueue drop for certain views. Then instead of removing those views it may decide to reuse tag that has been previously allocated for a view that is no longer in use. Special handling is required for layout-only nodes as they only can transition from layout-only to non-layout-only (reverse transition hasn't been implemented). Because of that we'd loose benefits of view flattening if we decide to recycle existing non-layout-only view as a layout-only one. This diff provides only a simple and manual method for configuring pools by calling `ReactNativeViewPool.configure` with a dict from native view name to the view count. Note that we may not want recycle all the views (e.g. when we render mapview we don't want to keep it in memory after it's detached) Reviewed By: davidaurelio Differential Revision: D2677289 fb-gh-sync-id: 29f44ce5b01db3ec353522af051b6a50924614a2
This commit is contained in:
committed by
facebook-github-bot-0
parent
0c8850f3a7
commit
205a35ad37
@@ -261,6 +261,23 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void dropViews(ReadableArray viewTags) {
|
||||
int size = viewTags.size(), realViewsCount = 0;
|
||||
int realViewTags[] = new int[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
int tag = viewTags.getInt(i);
|
||||
ReactShadowNode cssNode = mShadowNodeRegistry.getNode(tag);
|
||||
if (!cssNode.isVirtual()) {
|
||||
realViewTags[realViewsCount++] = tag;
|
||||
}
|
||||
mShadowNodeRegistry.removeNode(tag);
|
||||
}
|
||||
if (realViewsCount > 0) {
|
||||
mNativeViewHierarchyOptimizer.handleDropViews(realViewTags, realViewsCount);
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void updateView(int tag, String className, ReadableMap props) {
|
||||
ViewManager viewManager = mViewManagers.get(className);
|
||||
@@ -405,7 +422,6 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
|
||||
|
||||
private void removeShadowNode(ReactShadowNode nodeToRemove) {
|
||||
mNativeViewHierarchyOptimizer.handleRemoveNode(nodeToRemove);
|
||||
mShadowNodeRegistry.removeNode(nodeToRemove.getReactTag());
|
||||
for (int i = nodeToRemove.getChildCount() - 1; i >= 0; i--) {
|
||||
removeShadowNode(nodeToRemove.getChildAt(i));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user