Convert React Native builds to named exports (#18136)
These don't need any forks because we always export the same things atm.
Sebastian Markbåge committed
Feb 27, 2020 at 11:33 UTC
3e809bf5d46dbabdc2ccbec41e030c5cb1efeac4
5 files changed
+162
-153
packages/react-native-renderer/fabric.js
+6
-6
@@ -7,10 +7,10 @@
7
* @flow
8
*/
9
10
-'use strict';
10
+import type {ReactFabricType} from './src/ReactNativeTypes';
11
+import * as ReactFabric from './src/ReactFabric';
12
+// Assert that the exports line up with the type we're going to expose.
13
+// eslint-disable-next-line no-unused-expressions
14
+(ReactFabric: ReactFabricType);
15
12
-const ReactFabric = require('./src/ReactFabric');
13
-
14
-// TODO: decide on the top-level export form.
15
-// This is hacky but makes it work with both Rollup and Jest.
16
-module.exports = ReactFabric.default || ReactFabric;
16
+export * from './src/ReactFabric';
packages/react-native-renderer/index.js
+6
-6
@@ -7,10 +7,10 @@
7
* @flow
8
*/
9
10
-'use strict';
10
+import type {ReactNativeType} from './src/ReactNativeTypes';
11
+import * as ReactNative from './src/ReactNativeRenderer';
12
+// Assert that the exports line up with the type we're going to expose.
13
+// eslint-disable-next-line no-unused-expressions
14
+(ReactNative: ReactNativeType);
15
12
-const ReactNativeRenderer = require('./src/ReactNativeRenderer');
13
-
14
-// TODO: decide on the top-level export form.
15
-// This is hacky but makes it work with both Rollup and Jest.
16
-module.exports = ReactNativeRenderer.default || ReactNativeRenderer;
16
+export * from './src/ReactNativeRenderer';
packages/react-native-renderer/src/ReactFabric.js
+71
-66
@@ -7,7 +7,7 @@
7
* @flow
8
*/
9
10
-import type {ReactFabricType, HostComponent} from './ReactNativeTypes';
10
+import type {HostComponent} from './ReactNativeTypes';
11
import type {ReactNodeList} from 'shared/ReactTypes';
12
import type {ElementRef} from 'react';
13
@@ -26,7 +26,7 @@ import {
26
getPublicRootInstance,
27
} from 'react-reconciler/inline.fabric';
28
29
-import {createPortal} from 'shared/ReactPortal';
29
+import {createPortal as createPortalImpl} from 'shared/ReactPortal';
30
import {setBatchingImplementation} from 'legacy-events/ReactGenericBatching';
31
import ReactVersion from 'shared/ReactVersion';
32
@@ -144,6 +144,69 @@ function findNodeHandle(componentOrHandle: any): ?number {
144
return hostInstance._nativeTag;
145
}
146
147
+function dispatchCommand(handle: any, command: string, args: Array<any>) {
148
+ if (handle._nativeTag == null) {
149
+ if (__DEV__) {
150
+ console.error(
151
+ "dispatchCommand was called with a ref that isn't a " +
152
+ 'native component. Use React.forwardRef to get access to the underlying native component',
153
+ );
154
+ }
155
+
156
+ return;
157
+ }
158
+
159
+ if (handle._internalInstanceHandle) {
160
+ nativeFabricUIManager.dispatchCommand(
161
+ handle._internalInstanceHandle.stateNode.node,
162
+ command,
163
+ args,
164
+ );
165
+ } else {
166
+ UIManager.dispatchViewManagerCommand(handle._nativeTag, command, args);
167
+ }
168
+}
169
+
170
+function render(
171
+ element: React$Element<any>,
172
+ containerTag: any,
173
+ callback: ?Function,
174
+) {
175
+ let root = roots.get(containerTag);
176
+
177
+ if (!root) {
178
+ // TODO (bvaughn): If we decide to keep the wrapper component,
179
+ // We could create a wrapper for containerTag as well to reduce special casing.
180
+ root = createContainer(containerTag, LegacyRoot, false, null);
181
+ roots.set(containerTag, root);
182
+ }
183
+ updateContainer(element, root, null, callback);
184
+
185
+ return getPublicRootInstance(root);
186
+}
187
+
188
+function unmountComponentAtNode(containerTag: number) {
189
+ this.stopSurface(containerTag);
190
+}
191
+
192
+function stopSurface(containerTag: number) {
193
+ const root = roots.get(containerTag);
194
+ if (root) {
195
+ // TODO: Is it safe to reset this now or should I wait since this unmount could be deferred?
196
+ updateContainer(null, root, null, () => {
197
+ roots.delete(containerTag);
198
+ });
199
+ }
200
+}
201
+
202
+function createPortal(
203
+ children: ReactNodeList,
204
+ containerTag: number,
205
+ key: ?string = null,
206
+) {
207
+ return createPortalImpl(children, containerTag, null, key);
208
+}
209
+
210
setBatchingImplementation(
211
batchedUpdatesImpl,
212
discreteUpdates,
@@ -153,74 +216,18 @@ setBatchingImplementation(
216
217
const roots = new Map();
218
156
-const ReactFabric: ReactFabricType = {
219
+export {
220
// This is needed for implementation details of TouchableNativeFeedback
221
// Remove this once TouchableNativeFeedback doesn't use cloneElement
222
findHostInstance_DEPRECATED,
223
findNodeHandle,
161
-
162
- dispatchCommand(handle: any, command: string, args: Array<any>) {
163
- if (handle._nativeTag == null) {
164
- if (__DEV__) {
165
- console.error(
166
- "dispatchCommand was called with a ref that isn't a " +
167
- 'native component. Use React.forwardRef to get access to the underlying native component',
168
- );
169
- }
170
-
171
- return;
172
- }
173
-
174
- if (handle._internalInstanceHandle) {
175
- nativeFabricUIManager.dispatchCommand(
176
- handle._internalInstanceHandle.stateNode.node,
177
- command,
178
- args,
179
- );
180
- } else {
181
- UIManager.dispatchViewManagerCommand(handle._nativeTag, command, args);
182
- }
183
- },
184
-
185
- render(element: React$Element<any>, containerTag: any, callback: ?Function) {
186
- let root = roots.get(containerTag);
187
-
188
- if (!root) {
189
- // TODO (bvaughn): If we decide to keep the wrapper component,
190
- // We could create a wrapper for containerTag as well to reduce special casing.
191
- root = createContainer(containerTag, LegacyRoot, false, null);
192
- roots.set(containerTag, root);
193
- }
194
- updateContainer(element, root, null, callback);
195
-
196
- return getPublicRootInstance(root);
197
- },
198
-
224
+ dispatchCommand,
225
+ render,
226
// Deprecated - this function is being renamed to stopSurface, use that instead.
227
// TODO (T47576999): Delete this once it's no longer called from native code.
201
- unmountComponentAtNode(containerTag: number) {
202
- this.stopSurface(containerTag);
203
- },
204
-
205
- stopSurface(containerTag: number) {
206
- const root = roots.get(containerTag);
207
- if (root) {
208
- // TODO: Is it safe to reset this now or should I wait since this unmount could be deferred?
209
- updateContainer(null, root, null, () => {
210
- roots.delete(containerTag);
211
- });
212
- }
213
- },
214
-
215
- createPortal(
216
- children: ReactNodeList,
217
- containerTag: number,
218
- key: ?string = null,
219
- ) {
220
- return createPortal(children, containerTag, null, key);
221
- },
222
-
223
- __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {},
228
+ unmountComponentAtNode,
229
+ stopSurface,
230
+ createPortal,
231
};
232
233
injectIntoDevTools({
@@ -230,5 +237,3 @@ injectIntoDevTools({
237
version: ReactVersion,
238
rendererPackageName: 'react-native-renderer',
239
});
233
-
234
-export default ReactFabric;
packages/react-native-renderer/src/ReactNativeRenderer.js
+79
-72
@@ -7,7 +7,7 @@
7
* @flow
8
*/
9
10
-import type {ReactNativeType, HostComponent} from './ReactNativeTypes';
10
+import type {HostComponent} from './ReactNativeTypes';
11
import type {ReactNodeList} from 'shared/ReactTypes';
12
13
import './ReactNativeInjection';
@@ -26,7 +26,7 @@ import {
26
} from 'react-reconciler/inline.native';
27
// TODO: direct imports like some-package/src/* are bad. Fix me.
28
import {getStackByFiberInDevAndProd} from 'react-reconciler/src/ReactCurrentFiber';
29
-import {createPortal} from 'shared/ReactPortal';
29
+import {createPortal as createPortalImpl} from 'shared/ReactPortal';
30
import {
31
setBatchingImplementation,
32
batchedUpdates,
@@ -144,6 +144,71 @@ function findNodeHandle(componentOrHandle: any): ?number {
144
return hostInstance._nativeTag;
145
}
146
147
+function dispatchCommand(handle: any, command: string, args: Array<any>) {
148
+ if (handle._nativeTag == null) {
149
+ if (__DEV__) {
150
+ console.error(
151
+ "dispatchCommand was called with a ref that isn't a " +
152
+ 'native component. Use React.forwardRef to get access to the underlying native component',
153
+ );
154
+ }
155
+ return;
156
+ }
157
+
158
+ if (handle._internalInstanceHandle) {
159
+ nativeFabricUIManager.dispatchCommand(
160
+ handle._internalInstanceHandle.stateNode.node,
161
+ command,
162
+ args,
163
+ );
164
+ } else {
165
+ UIManager.dispatchViewManagerCommand(handle._nativeTag, command, args);
166
+ }
167
+}
168
+
169
+function render(
170
+ element: React$Element<any>,
171
+ containerTag: any,
172
+ callback: ?Function,
173
+) {
174
+ let root = roots.get(containerTag);
175
+
176
+ if (!root) {
177
+ // TODO (bvaughn): If we decide to keep the wrapper component,
178
+ // We could create a wrapper for containerTag as well to reduce special casing.
179
+ root = createContainer(containerTag, LegacyRoot, false, null);
180
+ roots.set(containerTag, root);
181
+ }
182
+ updateContainer(element, root, null, callback);
183
+
184
+ return getPublicRootInstance(root);
185
+}
186
+
187
+function unmountComponentAtNode(containerTag: number) {
188
+ const root = roots.get(containerTag);
189
+ if (root) {
190
+ // TODO: Is it safe to reset this now or should I wait since this unmount could be deferred?
191
+ updateContainer(null, root, null, () => {
192
+ roots.delete(containerTag);
193
+ });
194
+ }
195
+}
196
+
197
+function unmountComponentAtNodeAndRemoveContainer(containerTag: number) {
198
+ unmountComponentAtNode(containerTag);
199
+
200
+ // Call back into native to remove all of the subviews from this container
201
+ UIManager.removeRootView(containerTag);
202
+}
203
+
204
+function createPortal(
205
+ children: ReactNodeList,
206
+ containerTag: number,
207
+ key: ?string = null,
208
+) {
209
+ return createPortalImpl(children, containerTag, null, key);
210
+}
211
+
212
setBatchingImplementation(
213
batchedUpdatesImpl,
214
discreteUpdates,
@@ -161,78 +226,22 @@ function computeComponentStackForErrorReporting(reactTag: number): string {
226
227
const roots = new Map();
228
164
-const ReactNativeRenderer: ReactNativeType = {
229
+const Internals = {
230
+ computeComponentStackForErrorReporting,
231
+};
232
+
233
+export {
234
// This is needed for implementation details of TouchableNativeFeedback
235
// Remove this once TouchableNativeFeedback doesn't use cloneElement
236
findHostInstance_DEPRECATED,
237
findNodeHandle,
169
-
170
- dispatchCommand(handle: any, command: string, args: Array<any>) {
171
- if (handle._nativeTag == null) {
172
- if (__DEV__) {
173
- console.error(
174
- "dispatchCommand was called with a ref that isn't a " +
175
- 'native component. Use React.forwardRef to get access to the underlying native component',
176
- );
177
- }
178
- return;
179
- }
180
-
181
- if (handle._internalInstanceHandle) {
182
- nativeFabricUIManager.dispatchCommand(
183
- handle._internalInstanceHandle.stateNode.node,
184
- command,
185
- args,
186
- );
187
- } else {
188
- UIManager.dispatchViewManagerCommand(handle._nativeTag, command, args);
189
- }
190
- },
191
-
192
- render(element: React$Element<any>, containerTag: any, callback: ?Function) {
193
- let root = roots.get(containerTag);
194
-
195
- if (!root) {
196
- // TODO (bvaughn): If we decide to keep the wrapper component,
197
- // We could create a wrapper for containerTag as well to reduce special casing.
198
- root = createContainer(containerTag, LegacyRoot, false, null);
199
- roots.set(containerTag, root);
200
- }
201
- updateContainer(element, root, null, callback);
202
-
203
- return getPublicRootInstance(root);
204
- },
205
-
206
- unmountComponentAtNode(containerTag: number) {
207
- const root = roots.get(containerTag);
208
- if (root) {
209
- // TODO: Is it safe to reset this now or should I wait since this unmount could be deferred?
210
- updateContainer(null, root, null, () => {
211
- roots.delete(containerTag);
212
- });
213
- }
214
- },
215
-
216
- unmountComponentAtNodeAndRemoveContainer(containerTag: number) {
217
- ReactNativeRenderer.unmountComponentAtNode(containerTag);
218
-
219
- // Call back into native to remove all of the subviews from this container
220
- UIManager.removeRootView(containerTag);
221
- },
222
-
223
- createPortal(
224
- children: ReactNodeList,
225
- containerTag: number,
226
- key: ?string = null,
227
- ) {
228
- return createPortal(children, containerTag, null, key);
229
- },
230
-
231
- unstable_batchedUpdates: batchedUpdates,
232
-
233
- __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {
234
- computeComponentStackForErrorReporting,
235
- },
238
+ dispatchCommand,
239
+ render,
240
+ unmountComponentAtNode,
241
+ unmountComponentAtNodeAndRemoveContainer,
242
+ createPortal,
243
+ batchedUpdates as unstable_batchedUpdates,
244
+ Internals as __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
245
};
246
247
injectIntoDevTools({
@@ -242,5 +251,3 @@ injectIntoDevTools({
251
version: ReactVersion,
252
rendererPackageName: 'react-native-renderer',
253
});
245
-
246
-export default ReactNativeRenderer;
packages/react-native-renderer/src/ReactNativeTypes.js
-3
@@ -100,8 +100,6 @@ type SecretInternalsType = {
100
...
101
};
102
103
-type SecretInternalsFabricType = {...};
104
-
103
/**
104
* Flat ReactNative renderer bundles are too big for Flow to parse efficiently.
105
* Provide minimal Flow typing for the high-level RN API and call it a day.
@@ -137,7 +135,6 @@ export type ReactFabricType = {
135
callback: ?Function,
136
): any,
137
unmountComponentAtNode(containerTag: number): any,
140
- __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: SecretInternalsFabricType,
138
...
139
};
140