mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-27 19:25:11 +08:00
[react_native] JS files from D2163804: [react_native] Add native root tag to createView calls
This commit is contained in:
@@ -251,7 +251,14 @@ ReactNativeBaseComponent.Mixin = {
|
||||
this._currentElement.props, // next props
|
||||
this.viewConfig.validAttributes
|
||||
);
|
||||
RCTUIManager.createView(tag, this.viewConfig.uiViewClassName, updatePayload);
|
||||
|
||||
var nativeTopRootID = ReactNativeTagHandles.getNativeTopRootIDFromNodeID(rootID);
|
||||
RCTUIManager.createView(
|
||||
tag,
|
||||
this.viewConfig.uiViewClassName,
|
||||
nativeTopRootID ? ReactNativeTagHandles.rootNodeIDToTag[nativeTopRootID] : null,
|
||||
updatePayload
|
||||
);
|
||||
|
||||
this._registerListenersUponCreation(this._currentElement.props);
|
||||
this.initializeChildren(
|
||||
|
||||
@@ -28,6 +28,7 @@ var warning = require('warning');
|
||||
* unmount a component with a `rootNodeID`, then mount a new one in its place,
|
||||
*/
|
||||
var INITIAL_TAG_COUNT = 1;
|
||||
var NATIVE_TOP_ROOT_ID_SEPARATOR = '{TOP_LEVEL}';
|
||||
var ReactNativeTagHandles = {
|
||||
tagsStartAt: INITIAL_TAG_COUNT,
|
||||
tagCount: INITIAL_TAG_COUNT,
|
||||
@@ -67,7 +68,7 @@ var ReactNativeTagHandles = {
|
||||
this.reactTagIsNativeTopRootID(tag),
|
||||
'Expect a native root tag, instead got ', tag
|
||||
);
|
||||
return '.r[' + tag + ']{TOP_LEVEL}';
|
||||
return '.r[' + tag + ']' + NATIVE_TOP_ROOT_ID_SEPARATOR;
|
||||
},
|
||||
|
||||
reactTagIsNativeTopRootID: function(reactTag: number): bool {
|
||||
@@ -75,6 +76,17 @@ var ReactNativeTagHandles = {
|
||||
return reactTag % 10 === 1;
|
||||
},
|
||||
|
||||
getNativeTopRootIDFromNodeID: function(nodeID: ?string): ?string {
|
||||
if (!nodeID) {
|
||||
return null;
|
||||
}
|
||||
var index = nodeID.indexOf(NATIVE_TOP_ROOT_ID_SEPARATOR);
|
||||
if (index === -1) {
|
||||
return null;
|
||||
}
|
||||
return nodeID.substr(0, index + NATIVE_TOP_ROOT_ID_SEPARATOR.length);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the native `nodeHandle` (`tag`) that was most recently *natively*
|
||||
* mounted at the `rootNodeID`. Just because a React component has been
|
||||
|
||||
@@ -32,7 +32,13 @@ assign(ReactNativeTextComponent.prototype, {
|
||||
mountComponent: function(rootID, transaction, context) {
|
||||
this._rootNodeID = rootID;
|
||||
var tag = ReactNativeTagHandles.allocateTag();
|
||||
RCTUIManager.createView(tag, 'RCTRawText', {text: this._stringText});
|
||||
var nativeTopRootID = ReactNativeTagHandles.getNativeTopRootIDFromNodeID(rootID);
|
||||
RCTUIManager.createView(
|
||||
tag,
|
||||
'RCTRawText',
|
||||
nativeTopRootID ? ReactNativeTagHandles.rootNodeIDToTag[nativeTopRootID] : null,
|
||||
{text: this._stringText}
|
||||
);
|
||||
return {
|
||||
rootNodeID: rootID,
|
||||
tag: tag,
|
||||
|
||||
Reference in New Issue
Block a user