Refactor RootShadowNodeRegistry to make it ThreadSafe
Reviewed By: achen1 Differential Revision: D7417965 fbshipit-source-id: 90fa007242d2f00a315a4db25d2b6a0949e4b0d3
This commit is contained in:
parent
fd4bc72512
commit
9c805062e7
|
@ -270,7 +270,7 @@ public class FabricUIManager implements UIManager {
|
|||
mUIViewOperationQueue.dispatchViewUpdates(
|
||||
mCurrentBatch++, System.currentTimeMillis(), System.currentTimeMillis());
|
||||
|
||||
mRootShadowNodeRegistry.addNode(currentRootShadowNode);
|
||||
mRootShadowNodeRegistry.replaceNode(currentRootShadowNode);
|
||||
} catch (Exception e) {
|
||||
handleException(getRootNode(rootTag), e);
|
||||
}
|
||||
|
@ -320,7 +320,7 @@ public class FabricUIManager implements UIManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public synchronized <T extends SizeMonitoringFrameLayout & MeasureSpecProvider> int addRootView(
|
||||
public <T extends SizeMonitoringFrameLayout & MeasureSpecProvider> int addRootView(
|
||||
final T rootView) {
|
||||
int rootTag = ReactRootViewTagGenerator.getNextRootViewTag();
|
||||
ThemedReactContext themedRootContext =
|
||||
|
@ -332,7 +332,7 @@ public class FabricUIManager implements UIManager {
|
|||
int heightMeasureSpec = rootView.getHeightMeasureSpec();
|
||||
updateRootView(rootShadowNode, widthMeasureSpec, heightMeasureSpec);
|
||||
|
||||
mRootShadowNodeRegistry.addNode(rootShadowNode);
|
||||
mRootShadowNodeRegistry.registerNode(rootShadowNode);
|
||||
mUIViewOperationQueue.addRootView(rootTag, rootView, themedRootContext);
|
||||
return rootTag;
|
||||
}
|
||||
|
|
|
@ -7,30 +7,40 @@
|
|||
|
||||
package com.facebook.react.fabric;
|
||||
|
||||
import android.util.SparseArray;
|
||||
import com.facebook.react.uimanager.ReactShadowNode;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
/**
|
||||
* Simple container class to keep track of {@link ReactShadowNode}s that represents the Root
|
||||
* Shadow Nodes of a {@link FabricUIManager}
|
||||
* Shadow Nodes of a {@link FabricUIManager}.
|
||||
*/
|
||||
@ThreadSafe
|
||||
public class RootShadowNodeRegistry {
|
||||
|
||||
private final SparseArray<ReactShadowNode> mTagsToRootNodes;
|
||||
private final ConcurrentHashMap<Integer, ReactShadowNode> mTagsToRootNodes = new ConcurrentHashMap<>();
|
||||
|
||||
public RootShadowNodeRegistry() {
|
||||
mTagsToRootNodes = new SparseArray<>();
|
||||
}
|
||||
|
||||
public void addNode(ReactShadowNode node) {
|
||||
/**
|
||||
* Registers the {@link ReactShadowNode} received as a parameter as a RootShadowNode.
|
||||
*/
|
||||
public synchronized void registerNode(ReactShadowNode node) {
|
||||
mTagsToRootNodes.put(node.getReactTag(), node);
|
||||
}
|
||||
|
||||
public void removeNode(int tag) {
|
||||
/**
|
||||
* Register the {@link ReactShadowNode} received as a parameter as a RootShadowNode, replacing
|
||||
* the previous RootShadowNode associated for the {@link ReactShadowNode#getReactTag()}
|
||||
*/
|
||||
public void replaceNode(ReactShadowNode node) {
|
||||
mTagsToRootNodes.replace(node.getReactTag(), node);
|
||||
}
|
||||
|
||||
public void removeNode(Integer tag) {
|
||||
mTagsToRootNodes.remove(tag);
|
||||
}
|
||||
|
||||
public ReactShadowNode getNode(int tag) {
|
||||
return mTagsToRootNodes.get(tag);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue