diff --git a/scripts/rollup/shims/react-native/lazilyCreateReactNativeComponentClass.js b/scripts/rollup/shims/react-native/lazilyCreateReactNativeComponentClass.js deleted file mode 100644 index dc860dcf6b440..0000000000000 --- a/scripts/rollup/shims/react-native/lazilyCreateReactNativeComponentClass.js +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @providesModule lazilyCreateReactNativeComponentClass - * @flow - */ - -'use strict'; - -const { - __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, -} = require('ReactNative'); - -module.exports = - __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.lazilyCreateReactNativeComponentClass; diff --git a/src/renderers/native/ReactNativeFiberEntry.js b/src/renderers/native/ReactNativeFiberEntry.js index 8ece6236fbdab..d0f119cbde6a2 100644 --- a/src/renderers/native/ReactNativeFiberEntry.js +++ b/src/renderers/native/ReactNativeFiberEntry.js @@ -100,8 +100,7 @@ const ReactNativeFiber: ReactNativeType = { ReactNativeComponentTree: require('ReactNativeComponentTree'), // InspectorUtils, ScrollResponder ReactNativePropRegistry: require('ReactNativePropRegistry'), // flattenStyle, Stylesheet TouchHistoryMath: require('TouchHistoryMath'), // PanResponder - createReactNativeComponentClass: require('createReactNativeComponentClass'), // eg RCTText, ReactNativeART - lazilyCreateReactNativeComponentClass: require('lazilyCreateReactNativeComponentClass'), // eg RCTView + createReactNativeComponentClass: require('createReactNativeComponentClass'), // eg RCTText, RCTView, ReactNativeART takeSnapshot: require('takeSnapshot'), // react-native-implementation }, }; diff --git a/src/renderers/native/ReactNativeTypes.js b/src/renderers/native/ReactNativeTypes.js index 54b8a13de2257..2f5bea4048cae 100644 --- a/src/renderers/native/ReactNativeTypes.js +++ b/src/renderers/native/ReactNativeTypes.js @@ -62,9 +62,6 @@ export type NativeMethodsMixinType = { type SecretInternalsType = { NativeMethodsMixin: NativeMethodsMixinType, createReactNativeComponentClass( - viewConfig: ReactNativeBaseComponentViewConfig, - ): any, - lazilyCreateReactNativeComponentClass( name: string, callback: ViewConfigGetter, ): any, diff --git a/src/renderers/native/ReactNativeViewConfigRegistry.js b/src/renderers/native/ReactNativeViewConfigRegistry.js index cb98c7ea8db07..370a933706e9c 100644 --- a/src/renderers/native/ReactNativeViewConfigRegistry.js +++ b/src/renderers/native/ReactNativeViewConfigRegistry.js @@ -19,46 +19,32 @@ import type { ViewConfigGetter, } from 'ReactNativeTypes'; -const registeredViewNames = new Map(); const viewConfigCallbacks = new Map(); const viewConfigs = new Map(); const ReactNativeViewConfigRegistry = { - /** - * Registers a native view/component. - * This method is intended for views with JavaScript-defined configs. - * If the config is loaded from UIManager, use registerLazy() instead. - */ - register(viewConfig: ReactNativeBaseComponentViewConfig) { - const name = viewConfig.uiViewClassName; - invariant( - !registeredViewNames.has(name), - 'Tried to register two views with the same name %s', - name, - ); - viewConfigs.set(name, viewConfig); - registeredViewNames.set(name); - return name; - }, - /** * Registers a native view/component by name. * A callback is provided to load the view config from UIManager. * The callback is deferred until the view is actually rendered. * This is done to avoid causing Prepack deopts. */ - registerLazy(name: string, callback: ViewConfigGetter) { + register(name: string, callback: ViewConfigGetter): string { invariant( - !registeredViewNames.has(name), + !viewConfigCallbacks.has(name), 'Tried to register two views with the same name %s', name, ); viewConfigCallbacks.set(name, callback); - registeredViewNames.set(name); return name; }, - get(name: string) { + /** + * Retrieves a config for the specified view. + * If this is the first time the view has been used, + * This configuration will be lazy-loaded from UIManager. + */ + get(name: string): ReactNativeBaseComponentViewConfig { let viewConfig; if (!viewConfigs.has(name)) { const callback = viewConfigCallbacks.get(name); diff --git a/src/renderers/native/__tests__/ReactNativeEvents-test.js b/src/renderers/native/__tests__/ReactNativeEvents-test.js index 5a43e47c8df19..c46a8182985b3 100644 --- a/src/renderers/native/__tests__/ReactNativeEvents-test.js +++ b/src/renderers/native/__tests__/ReactNativeEvents-test.js @@ -34,10 +34,10 @@ beforeEach(() => { it('handles events', () => { expect(RCTEventEmitter.register.mock.calls.length).toBe(1); var EventEmitter = RCTEventEmitter.register.mock.calls[0][0]; - var View = createReactNativeComponentClass({ + var View = createReactNativeComponentClass('View', () => ({ validAttributes: {foo: true}, uiViewClassName: 'View', - }); + })); var log = []; ReactNative.render( @@ -94,10 +94,10 @@ it('handles events on text nodes', () => { expect(RCTEventEmitter.register.mock.calls.length).toBe(1); var EventEmitter = RCTEventEmitter.register.mock.calls[0][0]; - var Text = createReactNativeComponentClass({ + var Text = createReactNativeComponentClass('Text', () => ({ validAttributes: {foo: true}, uiViewClassName: 'Text', - }); + })); class ContextHack extends React.Component { static childContextTypes = {isInAParentText: PropTypes.bool}; @@ -179,10 +179,10 @@ it('handles events on text nodes', () => { it('handles when a responder is unmounted while a touch sequence is in progress', () => { var EventEmitter = RCTEventEmitter.register.mock.calls[0][0]; - var View = createReactNativeComponentClass({ + var View = createReactNativeComponentClass('View', () => ({ validAttributes: {id: true}, uiViewClassName: 'View', - }); + })); function getViewById(id) { return UIManager.createView.mock.calls.find( @@ -273,10 +273,10 @@ it('handles when a responder is unmounted while a touch sequence is in progress' it('handles events without target', () => { var EventEmitter = RCTEventEmitter.register.mock.calls[0][0]; - var View = createReactNativeComponentClass({ + var View = createReactNativeComponentClass('View', () => ({ validAttributes: {id: true}, uiViewClassName: 'View', - }); + })); function getViewById(id) { return UIManager.createView.mock.calls.find( diff --git a/src/renderers/native/__tests__/ReactNativeMount-test.js b/src/renderers/native/__tests__/ReactNativeMount-test.js index 5c434a7e49ad0..d9e04148553a4 100644 --- a/src/renderers/native/__tests__/ReactNativeMount-test.js +++ b/src/renderers/native/__tests__/ReactNativeMount-test.js @@ -27,10 +27,10 @@ describe('ReactNative', () => { }); it('should be able to create and render a native component', () => { - var View = createReactNativeComponentClass({ + var View = createReactNativeComponentClass('View', () => ({ validAttributes: {foo: true}, uiViewClassName: 'View', - }); + })); ReactNative.render(, 1); expect(UIManager.createView).toBeCalled(); @@ -40,10 +40,10 @@ describe('ReactNative', () => { }); it('should be able to create and update a native component', () => { - var View = createReactNativeComponentClass({ + var View = createReactNativeComponentClass('View', () => ({ validAttributes: {foo: true}, uiViewClassName: 'View', - }); + })); ReactNative.render(, 11); @@ -61,10 +61,10 @@ describe('ReactNative', () => { }); it('should not call UIManager.updateView after render for properties that have not changed', () => { - const Text = createReactNativeComponentClass({ + const Text = createReactNativeComponentClass('Text', () => ({ validAttributes: {foo: true}, uiViewClassName: 'Text', - }); + })); ReactNative.render(1, 11); expect(UIManager.updateView).not.toBeCalled(); @@ -87,10 +87,10 @@ describe('ReactNative', () => { }); it('should not call UIManager.updateView from setNativeProps for properties that have not changed', () => { - const View = createReactNativeComponentClass({ + const View = createReactNativeComponentClass('View', () => ({ validAttributes: {foo: true}, uiViewClassName: 'View', - }); + })); class Subclass extends ReactNative.NativeComponent { render() { @@ -122,10 +122,10 @@ describe('ReactNative', () => { }); it('returns the correct instance and calls it in the callback', () => { - var View = createReactNativeComponentClass({ + var View = createReactNativeComponentClass('View', () => ({ validAttributes: {foo: true}, uiViewClassName: 'View', - }); + })); var a; var b; @@ -143,10 +143,10 @@ describe('ReactNative', () => { }); it('renders and reorders children', () => { - var View = createReactNativeComponentClass({ + var View = createReactNativeComponentClass('View', () => ({ validAttributes: {title: true}, uiViewClassName: 'View', - }); + })); class Component extends React.Component { render() { diff --git a/src/renderers/native/__tests__/createReactNativeComponentClass-test.js b/src/renderers/native/__tests__/createReactNativeComponentClass-test.js index 58470bdca443c..7a225fb18769d 100644 --- a/src/renderers/native/__tests__/createReactNativeComponentClass-test.js +++ b/src/renderers/native/__tests__/createReactNativeComponentClass-test.js @@ -34,8 +34,14 @@ describe('createReactNativeComponentClass', () => { uiViewClassName: 'View', }; - const Text = createReactNativeComponentClass(textViewConfig); - const View = createReactNativeComponentClass(viewViewConfig); + const Text = createReactNativeComponentClass( + textViewConfig.uiViewClassName, + () => textViewConfig, + ); + const View = createReactNativeComponentClass( + viewViewConfig.uiViewClassName, + () => viewViewConfig, + ); expect(Text).not.toBe(View); @@ -53,10 +59,16 @@ describe('createReactNativeComponentClass', () => { uiViewClassName: 'Text', // Same }; - createReactNativeComponentClass(textViewConfig); + createReactNativeComponentClass( + textViewConfig.uiViewClassName, + () => textViewConfig, + ); expect(() => { - createReactNativeComponentClass(altTextViewConfig); + createReactNativeComponentClass( + altTextViewConfig.uiViewClassName, + () => altTextViewConfig, + ); }).toThrow('Tried to register two views with the same name Text'); }); }); diff --git a/src/renderers/native/createReactNativeComponentClass.js b/src/renderers/native/createReactNativeComponentClass.js index d7add6e513170..c9ed0d7d0d46e 100644 --- a/src/renderers/native/createReactNativeComponentClass.js +++ b/src/renderers/native/createReactNativeComponentClass.js @@ -14,20 +14,21 @@ const ReactNativeViewConfigRegistry = require('ReactNativeViewConfigRegistry'); -import type {ReactNativeBaseComponentViewConfig} from 'ReactNativeTypes'; +import type {ViewConfigGetter} from 'ReactNativeTypes'; /** * Creates a renderable ReactNative host component. - * Use this method when the view config is defined within JavaScript. - * Use lazilyCreateReactNativeComponentClass() for view configs retrieved from UIManager. + * Use this method for view configs that are loaded from UIManager. + * Use createReactNativeComponentClass() for view configs defined within JavaScript. * * @param {string} config iOS View configuration. * @private */ const createReactNativeComponentClass = function( - viewConfig: ReactNativeBaseComponentViewConfig, + name: string, + callback: ViewConfigGetter, ): string { - return ReactNativeViewConfigRegistry.register(viewConfig); + return ReactNativeViewConfigRegistry.register(name, callback); }; module.exports = createReactNativeComponentClass; diff --git a/src/renderers/native/lazilyCreateReactNativeComponentClass.js b/src/renderers/native/lazilyCreateReactNativeComponentClass.js deleted file mode 100644 index 17b4e059a6309..0000000000000 --- a/src/renderers/native/lazilyCreateReactNativeComponentClass.js +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @providesModule lazilyCreateReactNativeComponentClass - * @flow - */ - -'use strict'; - -const ReactNativeViewConfigRegistry = require('ReactNativeViewConfigRegistry'); - -import type {ViewConfigGetter} from 'ReactNativeTypes'; - -/** - * Creates a renderable ReactNative host component. - * Use this method for view configs that are loaded from UIManager. - * Use createReactNativeComponentClass() for view configs defined within JavaScript. - * - * @param {string} config iOS View configuration. - * @private - */ -const lazilyCreateReactNativeComponentClass = function( - name: string, - callback: ViewConfigGetter, -): string { - return ReactNativeViewConfigRegistry.registerLazy(name, callback); -}; - -module.exports = lazilyCreateReactNativeComponentClass;