mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-03 22:48:25 +08:00
Introducting UIManager.setLocalData(), the way to provide environmental data to ShadowNode
Summary: In some cases we need a way to provide some peice of data to shadow node to improve layout (or do something similar), `setLocalData` allows to do this. Reviewed By: AaaChiuuu Differential Revision: D5828368 fbshipit-source-id: bf6a04f460dc7695a16269426d365b78909bc8eb
This commit is contained in:
committed by
Facebook Github Bot
parent
abed3cf6c4
commit
d0790fea39
@@ -236,12 +236,20 @@ public class UIImplementation {
|
||||
cssNode.setStyleWidth(newWidth);
|
||||
cssNode.setStyleHeight(newHeight);
|
||||
|
||||
// If we're in the middle of a batch, the change will automatically be dispatched at the end of
|
||||
// the batch. As all batches are executed as a single runnable on the event queue this should
|
||||
// always be empty, but that calling architecture is an implementation detail.
|
||||
if (mOperationsQueue.isEmpty()) {
|
||||
dispatchViewUpdates(-1); // -1 = no associated batch id
|
||||
dispatchViewUpdatesIfNeeded();
|
||||
}
|
||||
|
||||
public void setViewLocalData(int tag, Object data) {
|
||||
ReactShadowNode shadowNode = mShadowNodeRegistry.getNode(tag);
|
||||
|
||||
if (shadowNode == null) {
|
||||
throw new IllegalViewOperationException(
|
||||
"Trying to set local data for view with unknown tag: " + tag);
|
||||
}
|
||||
|
||||
shadowNode.setLocalData(data);
|
||||
|
||||
dispatchViewUpdatesIfNeeded();
|
||||
}
|
||||
|
||||
public void profileNextBatch() {
|
||||
@@ -641,6 +649,17 @@ public class UIImplementation {
|
||||
}
|
||||
}
|
||||
|
||||
private void dispatchViewUpdatesIfNeeded() {
|
||||
// If we are in the middle of a batch update, any additional changes
|
||||
// will automatically be dispatched at the end of the batch.
|
||||
// If we are not, we have to initiate new batch update.
|
||||
// As all batches are executed as a single runnable on the event queue
|
||||
// this should always be empty, but that calling architecture is an implementation detail.
|
||||
if (mOperationsQueue.isEmpty()) {
|
||||
dispatchViewUpdates(-1); // "-1" means "no associated batch id"
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateViewHierarchy() {
|
||||
Systrace.beginSection(
|
||||
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
|
||||
|
||||
Reference in New Issue
Block a user