From e01f90784f961ad88a4cde114089bc5839207d29 Mon Sep 17 00:00:00 2001 From: Ben Alpert Date: Thu, 23 Jul 2015 17:50:16 -0700 Subject: [PATCH] [ReactNative] Update core RN modules to work with React 0.14-beta1 --- .flowconfig | 12 ++++--- Examples/UIExplorer/createExamplePage.js | 5 +-- Libraries/Components/ScrollView/ScrollView.js | 32 +++++++++--------- .../CustomComponents/ListView/ListView.js | 3 +- .../Initialization/ExceptionsManager.js | 5 +++ Libraries/ReactNative/ReactNative.js | 25 +++++--------- .../ReactNativeDefaultInjection.js | 2 +- Libraries/ReactNative/ReactNativeMount.js | 33 ++++++++++++++++--- packager/blacklist.js | 17 ++++------ 9 files changed, 78 insertions(+), 56 deletions(-) diff --git a/.flowconfig b/.flowconfig index 31a4d5317..ac39b85d9 100644 --- a/.flowconfig +++ b/.flowconfig @@ -9,11 +9,13 @@ # Ignore react-tools where there are overlaps, but don't ignore anything that # react-native relies on -.*/node_modules/react-tools/src/vendor/core/ExecutionEnvironment.js -.*/node_modules/react-tools/src/browser/eventPlugins/ResponderEventPlugin.js -.*/node_modules/react-tools/src/browser/ui/React.js -.*/node_modules/react-tools/src/core/ReactInstanceHandles.js -.*/node_modules/react-tools/src/event/EventPropagators.js +.*/node_modules/react-tools/src/React.js +.*/node_modules/react-tools/src/renderers/shared/reconciler/ReactInstanceHandles.js +.*/node_modules/react-tools/src/renderers/shared/event/EventPropagators.js +.*/node_modules/react-tools/src/renderers/shared/event/eventPlugins/ResponderEventPlugin.js +.*/node_modules/react-tools/src/renderers/shared/event/eventPlugins/ResponderSyntheticEvent.js +.*/node_modules/react-tools/src/renderers/shared/event/eventPlugins/ResponderTouchHistoryStore.js +.*/node_modules/react-tools/src/shared/vendor/core/ExecutionEnvironment.js # Ignore commoner tests .*/node_modules/commoner/test/.* diff --git a/Examples/UIExplorer/createExamplePage.js b/Examples/UIExplorer/createExamplePage.js index 352f84a4c..86525c485 100644 --- a/Examples/UIExplorer/createExamplePage.js +++ b/Examples/UIExplorer/createExamplePage.js @@ -54,8 +54,9 @@ var createExamplePage = function(title: ?string, exampleModule: ExampleModule) }; var result = example.render(null); if (result) { - renderedComponent = result; - result.props.navigator = this.props.navigator; + renderedComponent = React.cloneElement(result, { + navigator: this.props.navigator, + }); } (React: Object).render = originalRender; (React: Object).renderComponent = originalRenderComponent; diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index 48dd3c465..cd2dbf575 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -309,6 +309,21 @@ var ScrollView = React.createClass({ ); }, + handleScroll: function(e: Event) { + if (__DEV__) { + if (this.props.onScroll && !this.props.scrollEventThrottle) { + console.log( + 'You specified `onScroll` on a but not ' + + '`scrollEventThrottle`. You will only receive one event. ' + + 'Using `16` you get all the events but be aware that it may ' + + 'cause frame drops, use a bigger number if you don\'t need as ' + + 'much precision.' + ); + } + } + this.scrollResponderHandleScroll(e); + }, + render: function() { var contentContainerStyle = [ this.props.horizontal && styles.contentContainerHorizontal, @@ -324,21 +339,6 @@ var ScrollView = React.createClass({ ') must by applied through the contentContainerStyle prop.' ); } - if (__DEV__) { - if (this.props.onScroll && !this.props.scrollEventThrottle) { - var onScroll = this.props.onScroll; - this.props.onScroll = function() { - console.log( - 'You specified `onScroll` on a but not ' + - '`scrollEventThrottle`. You will only receive one event. ' + - 'Using `16` you get all the events but be aware that it may ' + - 'cause frame drops, use a bigger number if you don\'t need as ' + - 'much precision.' - ); - onScroll.apply(this, arguments); - }; - } - } var contentContainer = void) + ): ?ReactComponent { + warning('Use React.render instead of React.renderComponent'); + return ReactNative.render(element, mountInto, callback); + }, }; // Inject the runtime into a devtools global hook regardless of browser. diff --git a/Libraries/ReactNative/ReactNativeDefaultInjection.js b/Libraries/ReactNative/ReactNativeDefaultInjection.js index 15a3e5400..c95992402 100644 --- a/Libraries/ReactNative/ReactNativeDefaultInjection.js +++ b/Libraries/ReactNative/ReactNativeDefaultInjection.js @@ -90,7 +90,7 @@ function inject() { ReactNativeComponent.injection.injectTextComponentClass( ReactNativeTextComponent ); - ReactNativeComponent.injection.injectAutoWrapper(function(tag) { + ReactNativeComponent.injection.injectGenericComponentClass(function(tag) { // Show a nicer error message for non-function tags var info = ''; if (typeof tag === 'string' && /^[a-z]/.test(tag)) { diff --git a/Libraries/ReactNative/ReactNativeMount.js b/Libraries/ReactNative/ReactNativeMount.js index b61f1a243..631226764 100644 --- a/Libraries/ReactNative/ReactNativeMount.js +++ b/Libraries/ReactNative/ReactNativeMount.js @@ -13,6 +13,7 @@ var RCTUIManager = require('NativeModules').UIManager; +var ReactElement = require('ReactElement'); var ReactNativeTagHandles = require('ReactNativeTagHandles'); var ReactPerf = require('ReactPerf'); var ReactReconciler = require('ReactReconciler'); @@ -27,6 +28,17 @@ function instanceNumberToChildRootID(rootNodeID, instanceNumber) { return rootNodeID + '[' + instanceNumber + ']'; } +/** + * Temporary (?) hack so that we can store all top-level pending updates on + * composites instead of having to worry about different types of components + * here. + */ +var TopLevelWrapper = function() {}; +TopLevelWrapper.prototype.render = function() { + // this.props is actually a ReactElement + return this.props; +}; + /** * Mounts this component and inserts it into the DOM. * @@ -43,7 +55,7 @@ function mountComponentIntoNode( var markup = ReactReconciler.mountComponent( componentInstance, rootID, transaction, emptyObject ); - componentInstance._isTopLevel = true; + componentInstance._renderedComponent._topLevelWrapper = componentInstance; ReactNativeMount._mountImageIntoNode(markup, container); } @@ -94,13 +106,22 @@ var ReactNativeMount = { containerTag: number, callback?: ?(() => void) ): ?ReactComponent { + var nextWrappedElement = new ReactElement( + TopLevelWrapper, + null, + null, + null, + nextElement + ); + var topRootNodeID = ReactNativeTagHandles.tagToRootNodeID[containerTag]; if (topRootNodeID) { var prevComponent = ReactNativeMount._instancesByContainerID[topRootNodeID]; if (prevComponent) { - var prevElement = prevComponent._currentElement; + var prevWrappedElement = prevComponent._currentElement; + var prevElement = prevWrappedElement.props; if (shouldUpdateReactComponent(prevElement, nextElement)) { - ReactUpdateQueue.enqueueElementInternal(prevComponent, nextElement); + ReactUpdateQueue.enqueueElementInternal(prevComponent, nextWrappedElement); if (callback) { ReactUpdateQueue.enqueueCallbackInternal(prevComponent, callback); } @@ -122,7 +143,7 @@ var ReactNativeMount = { containerTag ); - var instance = instantiateReactComponent(nextElement); + var instance = instantiateReactComponent(nextWrappedElement); ReactNativeMount._instancesByContainerID[topRootNodeID] = instance; var childRootNodeID = instanceNumberToChildRootID( @@ -234,6 +255,10 @@ var ReactNativeMount = { getNode: function(id: T): T { return id; + }, + + getID: function(id: T): T { + return id; } }; diff --git a/packager/blacklist.js b/packager/blacklist.js index 237691a85..a1b9c946d 100644 --- a/packager/blacklist.js +++ b/packager/blacklist.js @@ -14,9 +14,13 @@ var path = require('path'); // modulePathIgnorePatterns. var sharedBlacklist = [ 'website', - 'node_modules/react-tools/src/utils/ImmutableObject.js', - 'node_modules/react-tools/src/core/ReactInstanceHandles.js', - 'node_modules/react-tools/src/event/EventPropagators.js' + 'node_modules/react-tools/src/React.js', + 'node_modules/react-tools/src/renderers/shared/event/EventPropagators.js', + 'node_modules/react-tools/src/renderers/shared/event/eventPlugins/ResponderEventPlugin.js', + 'node_modules/react-tools/src/renderers/shared/event/eventPlugins/ResponderSyntheticEvent.js', + 'node_modules/react-tools/src/renderers/shared/event/eventPlugins/ResponderTouchHistoryStore.js', + 'node_modules/react-tools/src/renderers/shared/reconciler/ReactInstanceHandles.js', + 'node_modules/react-tools/src/shared/vendor/core/ExecutionEnvironment.js', ]; var platformBlacklists = { @@ -24,17 +28,10 @@ var platformBlacklists = { '.ios.js' ], ios: [ - 'node_modules/react-tools/src/browser/ui/React.js', - 'node_modules/react-tools/src/browser/eventPlugins/ResponderEventPlugin.js', - 'node_modules/react-tools/src/vendor/core/ExecutionEnvironment.js', '.web.js', '.android.js', ], android: [ - 'node_modules/react-tools/src/browser/ui/React.js', - 'node_modules/react-tools/src/browser/eventPlugins/ResponderEventPlugin.js', - 'node_modules/react-tools/src/browser/ReactTextComponent.js', - 'node_modules/react-tools/src/vendor/core/ExecutionEnvironment.js', '.web.js', '.ios.js', ],