Skip to content

Commit b99d0b1

Browse files
authored
[RN] Move view config registry to shims (#12569)
* Move view config registry to shims This ensures that both Fabric and RN renderers share the same view config registry since it is stateful. I had to duplicate in the mocks for testing. * Move createReactNativeComponentClass to shims and delete internal usage Since createReactNativeComponentClass is just an alias for the register there's no need to bundle it. This file should probably just move back to RN too.
1 parent b6e0512 commit b99d0b1

19 files changed

+166
-91
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import ReactNativeComponent from './ReactNativeComponent';
2121
import * as ReactNativeComponentTree from './ReactNativeComponentTree';
2222
import ReactFabricRenderer from './ReactFabricRenderer';
2323
import {getInspectorDataForViewTag} from './ReactNativeFiberInspector';
24-
import createReactNativeComponentClass from './createReactNativeComponentClass';
2524
import {injectFindHostInstance} from './findNodeHandle';
2625
import findNumericNodeHandle from './findNumericNodeHandle';
2726

@@ -73,7 +72,6 @@ const ReactFabric: ReactFabricType = {
7372
NativeMethodsMixin,
7473
// Used by react-native-github/Libraries/ components
7574
ReactNativeComponentTree, // ScrollResponder
76-
createReactNativeComponentClass, // RCTText, RCTView, ReactNativeART
7775
},
7876
};
7977

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type {
1818
import {mountSafeCallback, warnForStyleProps} from './NativeMethodsMixinUtils';
1919
import * as ReactNativeAttributePayload from './ReactNativeAttributePayload';
2020
import * as ReactNativeFrameScheduling from './ReactNativeFrameScheduling';
21-
import * as ReactNativeViewConfigRegistry from './ReactNativeViewConfigRegistry';
21+
import * as ReactNativeViewConfigRegistry from 'ReactNativeViewConfigRegistry';
2222
import ReactFiberReconciler from 'react-reconciler';
2323

2424
import deepFreezeAndThrowOnMutationInDev from 'deepFreezeAndThrowOnMutationInDev';

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
accumulateTwoPhaseDispatches,
1313
accumulateDirectDispatches,
1414
} from 'events/EventPropagators';
15-
import * as ReactNativeViewConfigRegistry from './ReactNativeViewConfigRegistry';
15+
import * as ReactNativeViewConfigRegistry from 'ReactNativeViewConfigRegistry';
1616
import SyntheticEvent from 'events/SyntheticEvent';
1717
import invariant from 'fbjs/lib/invariant';
1818

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import invariant from 'fbjs/lib/invariant';
1616
import UIManager from 'UIManager';
1717
import deepFreezeAndThrowOnMutationInDev from 'deepFreezeAndThrowOnMutationInDev';
1818

19-
import * as ReactNativeViewConfigRegistry from './ReactNativeViewConfigRegistry';
19+
import * as ReactNativeViewConfigRegistry from 'ReactNativeViewConfigRegistry';
2020
import * as ReactNativeAttributePayload from './ReactNativeAttributePayload';
2121
import {
2222
precacheFiberNode,

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import ReactNativeComponent from './ReactNativeComponent';
2525
import * as ReactNativeComponentTree from './ReactNativeComponentTree';
2626
import ReactNativeFiberRenderer from './ReactNativeFiberRenderer';
2727
import {getInspectorDataForViewTag} from './ReactNativeFiberInspector';
28-
import createReactNativeComponentClass from './createReactNativeComponentClass';
2928
import {injectFindHostInstance} from './findNodeHandle';
3029
import findNumericNodeHandle from './findNumericNodeHandle';
3130

@@ -98,7 +97,6 @@ const ReactNativeRenderer: ReactNativeType = {
9897
NativeMethodsMixin,
9998
// Used by react-native-github/Libraries/ components
10099
ReactNativeComponentTree, // ScrollResponder
101-
createReactNativeComponentClass, // RCTText, RCTView, ReactNativeART
102100
computeComponentStackForErrorReporting,
103101
},
104102
};

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ export type NativeMethodsMixinType = {
7171

7272
type SecretInternalsType = {
7373
NativeMethodsMixin: NativeMethodsMixinType,
74-
createReactNativeComponentClass(
75-
name: string,
76-
callback: ViewConfigGetter,
77-
): any,
7874
ReactNativeComponentTree: any,
7975
// TODO (bvaughn) Decide which additional types to expose here?
8076
// And how much information to fill in for the above types.

packages/react-native-renderer/src/ReactNativeViewConfigRegistry.js renamed to packages/react-native-renderer/src/__mocks__/ReactNativeViewConfigRegistry.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,23 @@
66
*
77
* @flow
88
*/
9+
'use strict';
910

1011
import type {
1112
ReactNativeBaseComponentViewConfig,
1213
ViewConfigGetter,
1314
} from './ReactNativeTypes';
1415

15-
import invariant from 'fbjs/lib/invariant';
16+
const invariant = require('fbjs/lib/invariant');
1617

1718
// Event configs
18-
export const customBubblingEventTypes = {};
19-
export const customDirectEventTypes = {};
20-
export const eventTypes = {};
19+
const customBubblingEventTypes = {};
20+
const customDirectEventTypes = {};
21+
const eventTypes = {};
22+
23+
exports.customBubblingEventTypes = customBubblingEventTypes;
24+
exports.customDirectEventTypes = customDirectEventTypes;
25+
exports.eventTypes = eventTypes;
2126

2227
const viewConfigCallbacks = new Map();
2328
const viewConfigs = new Map();
@@ -64,22 +69,22 @@ function processEventTypes(
6469
* The callback is deferred until the view is actually rendered.
6570
* This is done to avoid causing Prepack deopts.
6671
*/
67-
export function register(name: string, callback: ViewConfigGetter): string {
72+
exports.register = function(name: string, callback: ViewConfigGetter): string {
6873
invariant(
6974
!viewConfigCallbacks.has(name),
7075
'Tried to register two views with the same name %s',
7176
name,
7277
);
7378
viewConfigCallbacks.set(name, callback);
7479
return name;
75-
}
80+
};
7681

7782
/**
7883
* Retrieves a config for the specified view.
7984
* If this is the first time the view has been used,
8085
* This configuration will be lazy-loaded from UIManager.
8186
*/
82-
export function get(name: string): ReactNativeBaseComponentViewConfig {
87+
exports.get = function(name: string): ReactNativeBaseComponentViewConfig {
8388
let viewConfig;
8489
if (!viewConfigs.has(name)) {
8590
const callback = viewConfigCallbacks.get(name);
@@ -97,4 +102,4 @@ export function get(name: string): ReactNativeBaseComponentViewConfig {
97102
}
98103
invariant(viewConfig, 'View config not found for name %s', name);
99104
return viewConfig;
100-
}
105+
};

packages/react-native-renderer/src/__mocks__/View.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ describe('ReactFabric', () => {
2828
ReactFabric = require('react-native-renderer/fabric');
2929
FabricUIManager = require('FabricUIManager');
3030
UIManager = require('UIManager');
31-
createReactNativeComponentClass = require('../createReactNativeComponentClass')
32-
.default;
31+
createReactNativeComponentClass = require('ReactNativeViewConfigRegistry')
32+
.register;
3333
});
3434

3535
it('should be able to create and render a native component', () => {

packages/react-native-renderer/src/__tests__/ReactFabricAndNative-test.internal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ describe('ReactFabric', () => {
2626

2727
React = require('react');
2828
ReactFabric = require('react-native-renderer/fabric');
29-
createReactNativeComponentClass = require('../createReactNativeComponentClass')
30-
.default;
29+
createReactNativeComponentClass = require('ReactNativeViewConfigRegistry')
30+
.register;
3131
});
3232

3333
it('find Fabric nodes with the RN renderer', () => {

0 commit comments

Comments
 (0)