mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-02 09:21:44 +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
@@ -324,6 +324,29 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
|
||||
mUIImplementation.updateNodeSize(nodeViewTag, newWidth, newHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets local data for a shadow node corresponded with given tag.
|
||||
* In some cases we need a way to specify some environmental data to shadow node
|
||||
* to improve layout (or do something similar), so {@code localData} serves these needs.
|
||||
* For example, any stateful embedded native views may benefit from this.
|
||||
* Have in mind that this data is not supposed to interfere with the state of
|
||||
* the shadow view.
|
||||
* Please respect one-directional data flow of React.
|
||||
*/
|
||||
public void setViewLocalData(final int tag, final Object data) {
|
||||
final ReactApplicationContext reactApplicationContext = getReactApplicationContext();
|
||||
|
||||
reactApplicationContext.assertOnUiQueueThread();
|
||||
|
||||
reactApplicationContext.runUIBackgroundRunnable(
|
||||
new GuardedRunnable(reactApplicationContext) {
|
||||
@Override
|
||||
public void runGuarded() {
|
||||
mUIImplementation.setViewLocalData(tag, data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void createView(int tag, String className, int rootViewTag, ReadableMap props) {
|
||||
if (DEBUG) {
|
||||
|
||||
Reference in New Issue
Block a user