Skip to content

Commit 1d34f91

Browse files
authored
[RN] Move RN globals to RN private interface module (#37550)
## Summary ReactNativeFeatureFlags and fabricUIManager were introduced in `react-native/react-private-interface` in react/react-native#57940 and react/react-native#58398: https://github.com/react/react-native/blob/73a76ddced2088d925809432fd6b0503f239dbfe/packages/react-native/src/react-private-interface.js#L74 https://github.com/react/react-native/blob/73a76ddced2088d925809432fd6b0503f239dbfe/packages/react-native/src/react-private-interface.js#L87 This migrates the use of globals for those bindings to use the exported values instead. ## How did you test this change? Existing tests and Flow.
1 parent 78c2d37 commit 1d34f91

12 files changed

Lines changed: 182 additions & 209 deletions

.eslintrc.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,6 @@ module.exports = {
458458
'eslint-plugin/require-meta-has-suggestions': ERROR,
459459
},
460460
},
461-
{
462-
files: ['packages/react-native-renderer/**/*.js'],
463-
globals: {
464-
nativeFabricUIManager: 'readonly',
465-
RN$isNativeEventTargetEventDispatchingEnabled: 'readonly',
466-
},
467-
},
468461
{
469462
files: ['packages/react-server-dom-webpack/**/*.js'],
470463
globals: {

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
* @flow
88
*/
99

10+
// Modules provided by RN:
11+
import {fabricUIManager} from 'react-native/react-private-interface';
12+
1013
const ReactFabricGlobalResponderHandler = {
1114
onChange: function (from: any, to: any, blockNativeResponder: boolean) {
1215
if (from && from.stateNode) {
1316
// equivalent to clearJSResponder
14-
nativeFabricUIManager.setIsJSResponder(
17+
fabricUIManager.setIsJSResponder(
1518
from.stateNode.node,
1619
false,
1720
blockNativeResponder || false,
@@ -20,7 +23,7 @@ const ReactFabricGlobalResponderHandler = {
2023

2124
if (to && to.stateNode) {
2225
// equivalent to setJSResponder
23-
nativeFabricUIManager.setIsJSResponder(
26+
fabricUIManager.setIsJSResponder(
2427
to.stateNode.node,
2528
true,
2629
blockNativeResponder || false,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
createPublicTextInstance,
3737
createAttributePayload,
3838
diffAttributePayloads,
39+
fabricUIManager,
3940
type PublicInstance as ReactNativePublicInstance,
4041
type PublicTextInstance,
4142
type PublicRootInstance,
@@ -61,7 +62,7 @@ const {
6162
unstable_IdleEventPriority: FabricIdlePriority,
6263
unstable_getCurrentEventPriority: fabricGetCurrentEventPriority,
6364
suspendOnActiveViewTransition: fabricSuspendOnActiveViewTransition,
64-
} = nativeFabricUIManager;
65+
} = fabricUIManager;
6566

6667
import {getClosestInstanceFromNode} from './ReactFabricComponentTree';
6768
import {compareDocumentPositionForEmptyFragment} from 'shared/ReactDOMFragmentRefShared';

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ import type {
1818

1919
import {allocateTag} from './ReactFiberConfigFabric';
2020

21+
// Modules provided by RN:
22+
import {fabricUIManager} from 'react-native/react-private-interface';
23+
2124
const {
2225
applyViewTransitionName: fabricApplyViewTransitionName,
2326
createViewTransitionInstance: fabricCreateViewTransitionInstance,
2427
startViewTransition: fabricStartViewTransition,
2528
startViewTransitionReadyFinished: fabricStartViewTransitionReadyFinished,
26-
} = nativeFabricUIManager;
29+
} = fabricUIManager;
2730

2831
export type InstanceMeasurement = {
2932
rect: {x: number, y: number, width: number, height: number},

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,23 @@
77
* @flow
88
*/
99

10-
// These globals are set by React Native (e.g. in setUpDOM.js, setUpTimers.js)
11-
// and provide access to RN's feature flags. We use global functions because we
12-
// don't have another mechanism to pass feature flags from RN to React in OSS.
10+
// Modules provided by RN:
11+
import {ReactNativeFeatureFlags} from 'react-native/react-private-interface';
12+
13+
// These accessors are provided by React Native and give us access to RN's
14+
// feature flags. Both the object and each accessor on it are treated as
15+
// optional so that removing a flag on the React Native side doesn't throw here.
1316
// Values are lazily evaluated and cached on first access.
1417

1518
let _enableNativeEventTargetEventDispatching: boolean | null = null;
1619
export function enableNativeEventTargetEventDispatching(): boolean {
1720
if (_enableNativeEventTargetEventDispatching == null) {
21+
const isEnabled =
22+
ReactNativeFeatureFlags != null
23+
? ReactNativeFeatureFlags.enableNativeEventTargetEventDispatching
24+
: null;
1825
_enableNativeEventTargetEventDispatching =
19-
typeof RN$isNativeEventTargetEventDispatchingEnabled === 'function' &&
20-
RN$isNativeEventTargetEventDispatchingEnabled();
26+
typeof isEnabled === 'function' && isEnabled();
2127
}
2228
return _enableNativeEventTargetEventDispatching;
2329
}

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ import {
1616
} from 'react-reconciler/src/ReactFiberTreeReflection';
1717
import getComponentNameFromType from 'shared/getComponentNameFromType';
1818
import {HostComponent} from 'react-reconciler/src/ReactWorkTags';
19-
// Module provided by RN:
20-
import {getNodeFromPublicInstance} from 'react-native/react-private-interface';
19+
// Modules provided by RN:
20+
import {
21+
getNodeFromPublicInstance,
22+
fabricUIManager,
23+
} from 'react-native/react-private-interface';
2124
import {getNodeFromInternalInstanceHandle} from './ReactNativePublicCompat';
2225
import {getStackByFiberInDevAndProd} from 'react-reconciler/src/ReactFiberComponentStack';
2326

@@ -43,7 +46,7 @@ if (__DEV__) {
4346
hostFiber.stateNode.node;
4447

4548
if (node) {
46-
nativeFabricUIManager.measure(node, callback);
49+
fabricUIManager.measure(node, callback);
4750
}
4851
},
4952
};
@@ -142,7 +145,7 @@ function getInspectorDataForViewAtPoint(
142145
const fabricNode = getNodeFromPublicInstance(inspectedView);
143146
if (fabricNode) {
144147
// For Fabric we can look up the instance handle directly and measure it.
145-
nativeFabricUIManager.findNodeAtPoint(
148+
fabricUIManager.findNodeAtPoint(
146149
fabricNode,
147150
locationX,
148151
locationY,
@@ -169,20 +172,16 @@ function getInspectorDataForViewAtPoint(
169172
const nativeViewTag =
170173
internalInstanceHandle.stateNode.canonical.nativeTag;
171174

172-
nativeFabricUIManager.measure(
173-
node,
174-
(x, y, width, height, pageX, pageY) => {
175-
const inspectorData =
176-
getInspectorDataForInstance(closestInstance);
177-
callback({
178-
...inspectorData,
179-
pointerY: locationY,
180-
frame: {left: pageX, top: pageY, width, height},
181-
touchedViewTag: nativeViewTag,
182-
closestPublicInstance,
183-
});
184-
},
185-
);
175+
fabricUIManager.measure(node, (x, y, width, height, pageX, pageY) => {
176+
const inspectorData = getInspectorDataForInstance(closestInstance);
177+
callback({
178+
...inspectorData,
179+
pointerY: locationY,
180+
frame: {left: pageX, top: pageY, width, height},
181+
touchedViewTag: nativeViewTag,
182+
closestPublicInstance,
183+
});
184+
});
186185
},
187186
);
188187
} else {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
getNodeFromPublicInstance,
1717
getNativeTagFromPublicInstance,
1818
getInternalInstanceHandleFromPublicInstance,
19+
fabricUIManager,
1920
} from 'react-native/react-private-interface';
2021

2122
import {
@@ -148,7 +149,7 @@ export function dispatchCommand(
148149
const node = getNodeFromPublicInstance(handle);
149150

150151
if (node != null) {
151-
nativeFabricUIManager.dispatchCommand(node, command, args);
152+
fabricUIManager.dispatchCommand(node, command, args);
152153
} else {
153154
if (__DEV__) {
154155
console.error(
@@ -163,7 +164,7 @@ export function sendAccessibilityEvent(handle: any, eventType: string) {
163164
const node = getNodeFromPublicInstance(handle);
164165

165166
if (node != null) {
166-
nativeFabricUIManager.sendAccessibilityEvent(node, eventType);
167+
fabricUIManager.sendAccessibilityEvent(node, eventType);
167168
} else {
168169
if (__DEV__) {
169170
console.error(
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict-local
8+
*/
9+
10+
module.exports = {
11+
enableNativeEventTargetEventDispatching(): boolean {
12+
return false;
13+
},
14+
};

packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/ReactNativePrivateInterface.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@
88
*/
99

1010
module.exports = {
11+
get fabricUIManager() {
12+
return global.nativeFabricUIManager;
13+
},
1114
get ReactFiberErrorDialog() {
1215
return require('./ReactFiberErrorDialog');
1316
},
17+
get ReactNativeFeatureFlags() {
18+
return require('./ReactNativeFeatureFlags');
19+
},
1420
get ReactNativeViewConfigRegistry() {
1521
return require('./ReactNativeViewConfigRegistry');
1622
},

0 commit comments

Comments
 (0)