From 3029511ce4f2d6f2d4ae90d169442b3ef01dd7f2 Mon Sep 17 00:00:00 2001 From: Andy Street Date: Thu, 18 Jun 2015 05:26:23 -0700 Subject: [PATCH] [react_native] JS files from D2163804: [react_native] Add native root tag to createView calls --- Libraries/ReactNative/ReactNativeBaseComponent.js | 9 ++++++++- Libraries/ReactNative/ReactNativeTagHandles.js | 14 +++++++++++++- Libraries/ReactNative/ReactNativeTextComponent.js | 8 +++++++- React/Modules/RCTUIManager.m | 1 + 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Libraries/ReactNative/ReactNativeBaseComponent.js b/Libraries/ReactNative/ReactNativeBaseComponent.js index 95af29023..84baf6753 100644 --- a/Libraries/ReactNative/ReactNativeBaseComponent.js +++ b/Libraries/ReactNative/ReactNativeBaseComponent.js @@ -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( diff --git a/Libraries/ReactNative/ReactNativeTagHandles.js b/Libraries/ReactNative/ReactNativeTagHandles.js index bf1dc59f2..ab350817c 100644 --- a/Libraries/ReactNative/ReactNativeTagHandles.js +++ b/Libraries/ReactNative/ReactNativeTagHandles.js @@ -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 diff --git a/Libraries/ReactNative/ReactNativeTextComponent.js b/Libraries/ReactNative/ReactNativeTextComponent.js index bdca141c0..bb93b9c34 100644 --- a/Libraries/ReactNative/ReactNativeTextComponent.js +++ b/Libraries/ReactNative/ReactNativeTextComponent.js @@ -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, diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index ff1691b8a..873265479 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -804,6 +804,7 @@ static void RCTSetShadowViewProps(NSDictionary *props, RCTShadowView *shadowView RCT_EXPORT_METHOD(createView:(NSNumber *)reactTag viewName:(NSString *)viewName + rootTag:(NSNumber *)rootTag props:(NSDictionary *)props) { RCTViewManager *manager = _viewManagers[viewName];