Skip to content

Commit 10eab79

Browse files
committed
[react-native] Use path-based imports instead of Haste for the RN renderer
To move React Native to standard path-based imports instead of Haste, the RN renderer that is generated from the code in this repo needs to use path-based imports as well since the generated code is vendored by RN. This commit makes it so the interface between the generated renderers and RN does not rely on Haste and instead uses a private interface explicitly defined by RN. This inverts control of the abstraction so that RN decides the internals to export rather than React deciding what to import. On RN's side, a new module named `react-native/Libraries/ReactPrivate/ReactNativePrivateInterface` explicitly exports the modules used by the renderers in this repo. (There is also a private module for InitializeCore so that we can import it just for the side effects.) On React's side, the various renderer modules access RN internals through the explicit private interface. The Rollup configuration becomes slimmer since the only external package is now `react-native`, and the individual modules are instead listed out in `ReactNativePrivateInterface`. Task description: facebook/react-native#24770 Sister RN PR (needs to land before this one): facebook/react-native#24782 Test Plan: Ran unit tests and Flow in this repo. Generated the renderers and manually copied them over to the RN repo. Ran the RN tests and launched the RNTester app.
1 parent 05d0850 commit 10eab79

37 files changed

+239
-237
lines changed

packages/react-native-renderer/src/NativeMethodsMixin.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ import type {
1717

1818
import invariant from 'shared/invariant';
1919
// Modules provided by RN:
20-
import TextInputState from 'TextInputState';
21-
import UIManager from 'UIManager';
20+
import {
21+
TextInputState,
22+
UIManager,
23+
} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
2224

2325
import {create} from './ReactNativeAttributePayload';
2426
import {

packages/react-native-renderer/src/ReactFabricGlobalResponderHandler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
// Module provided by RN:
11-
import UIManager from 'UIManager';
11+
import {UIManager} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
1212

1313
const ReactFabricGlobalResponderHandler = {
1414
onChange: function(from: any, to: any, blockNativeResponder: boolean) {

packages/react-native-renderer/src/ReactFabricHostConfig.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,37 @@ import type {ReactEventComponentInstance} from 'shared/ReactTypes';
1818

1919
import {mountSafeCallback_NOT_REALLY_SAFE} from './NativeMethodsMixinUtils';
2020
import {create, diff} from './ReactNativeAttributePayload';
21-
import {get as getViewConfigForType} from 'ReactNativeViewConfigRegistry';
2221

23-
import deepFreezeAndThrowOnMutationInDev from 'deepFreezeAndThrowOnMutationInDev';
2422
import invariant from 'shared/invariant';
2523
import warningWithoutStack from 'shared/warningWithoutStack';
2624

2725
import {dispatchEvent} from './ReactFabricEventEmitter';
2826

2927
// Modules provided by RN:
30-
import TextInputState from 'TextInputState';
3128
import {
29+
FabricUIManager,
30+
ReactNativeViewConfigRegistry,
31+
TextInputState,
32+
deepFreezeAndThrowOnMutationInDev,
33+
} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
34+
35+
const {
3236
createNode,
3337
cloneNode,
3438
cloneNodeWithNewChildren,
3539
cloneNodeWithNewChildrenAndProps,
3640
cloneNodeWithNewProps,
37-
createChildSet as createChildNodeSet,
38-
appendChild as appendChildNode,
39-
appendChildToSet as appendChildNodeToSet,
41+
createChildSet: createChildNodeSet,
42+
appendChild: appendChildNode,
43+
appendChildToSet: appendChildNodeToSet,
4044
completeRoot,
4145
registerEventHandler,
42-
measure as fabricMeasure,
43-
measureInWindow as fabricMeasureInWindow,
44-
measureLayout as fabricMeasureLayout,
45-
} from 'FabricUIManager';
46+
measure: fabricMeasure,
47+
measureInWindow: fabricMeasureInWindow,
48+
measureLayout: fabricMeasureLayout,
49+
} = FabricUIManager;
50+
51+
const {get: getViewConfigForType} = ReactNativeViewConfigRegistry;
4652

4753
// Counter for uniquely identifying views.
4854
// % 10 === 1 means it is a rootTag.

packages/react-native-renderer/src/ReactNativeAttributePayload.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
*/
99

1010
// Modules provided by RN:
11-
import deepDiffer from 'deepDiffer';
12-
import flattenStyle from 'flattenStyle';
11+
import {
12+
deepDiffer,
13+
flattenStyle,
14+
} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
1315

1416
import type {AttributeConfiguration} from './ReactNativeTypes';
1517

packages/react-native-renderer/src/ReactNativeBridgeEventPlugin.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ import {
1313
accumulateDirectDispatches,
1414
} from 'events/EventPropagators';
1515
import type {TopLevelType} from 'events/TopLevelEventTypes';
16-
import {
16+
import SyntheticEvent from 'events/SyntheticEvent';
17+
import invariant from 'shared/invariant';
18+
19+
// Module provided by RN:
20+
import {ReactNativeViewConfigRegistry} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
21+
22+
const {
1723
customBubblingEventTypes,
1824
customDirectEventTypes,
1925
eventTypes,
20-
} from 'ReactNativeViewConfigRegistry';
21-
import SyntheticEvent from 'events/SyntheticEvent';
22-
import invariant from 'shared/invariant';
26+
} = ReactNativeViewConfigRegistry;
2327

2428
const ReactNativeBridgeEventPlugin = {
2529
eventTypes: eventTypes,

packages/react-native-renderer/src/ReactNativeComponent.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ import type {
1818

1919
import React from 'react';
2020
// Modules provided by RN:
21-
import TextInputState from 'TextInputState';
22-
import UIManager from 'UIManager';
21+
import {
22+
TextInputState,
23+
UIManager,
24+
} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
2325

2426
import {create} from './ReactNativeAttributePayload';
2527
import {mountSafeCallback_NOT_REALLY_SAFE} from './NativeMethodsMixinUtils';

packages/react-native-renderer/src/ReactNativeFiberHostComponent.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ import type {
1717
import type {Instance} from './ReactNativeHostConfig';
1818

1919
// Modules provided by RN:
20-
import TextInputState from 'TextInputState';
21-
import UIManager from 'UIManager';
20+
import {
21+
TextInputState,
22+
UIManager,
23+
} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
2224

2325
import {create} from './ReactNativeAttributePayload';
2426
import {

packages/react-native-renderer/src/ReactNativeFiberInspector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import getComponentName from 'shared/getComponentName';
1717
import {HostComponent} from 'shared/ReactWorkTags';
1818
import invariant from 'shared/invariant';
1919
// Module provided by RN:
20-
import UIManager from 'UIManager';
20+
import {UIManager} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
2121

2222
import {getClosestInstanceFromNode} from './ReactNativeComponentTree';
2323

packages/react-native-renderer/src/ReactNativeGlobalResponderHandler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
// Module provided by RN:
11-
import UIManager from 'UIManager';
11+
import {UIManager} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
1212

1313
const ReactNativeGlobalResponderHandler = {
1414
onChange: function(from: any, to: any, blockNativeResponder: boolean) {

packages/react-native-renderer/src/ReactNativeHostConfig.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import type {ReactEventComponentInstance} from 'shared/ReactTypes';
1313
import invariant from 'shared/invariant';
1414

1515
// Modules provided by RN:
16-
import UIManager from 'UIManager';
17-
import deepFreezeAndThrowOnMutationInDev from 'deepFreezeAndThrowOnMutationInDev';
16+
import {
17+
ReactNativeViewConfigRegistry,
18+
UIManager,
19+
deepFreezeAndThrowOnMutationInDev,
20+
} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
1821

19-
import {get as getViewConfigForType} from 'ReactNativeViewConfigRegistry';
2022
import {create, diff} from './ReactNativeAttributePayload';
2123
import {
2224
precacheFiberNode,
@@ -25,6 +27,8 @@ import {
2527
} from './ReactNativeComponentTree';
2628
import ReactNativeFiberHostComponent from './ReactNativeFiberHostComponent';
2729

30+
const {get: getViewConfigForType} = ReactNativeViewConfigRegistry;
31+
2832
export type Type = string;
2933
export type Props = Object;
3034
export type Container = number;

0 commit comments

Comments
 (0)