Skip to content

Commit d0fc0ba

Browse files
authored
Revert "Dispatch commands to both UIManagers from both renderers (facebook#17211)" (facebook#17232)
This reverts commit 8eee0eb.
1 parent bdcdb69 commit d0fc0ba

File tree

3 files changed

+16
-108
lines changed

3 files changed

+16
-108
lines changed

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ import {createPortal} from 'shared/ReactPortal';
2929
import {setBatchingImplementation} from 'legacy-events/ReactGenericBatching';
3030
import ReactVersion from 'shared/ReactVersion';
3131

32-
// Module provided by RN:
33-
import {UIManager} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
34-
3532
import NativeMethodsMixin from './NativeMethodsMixin';
3633
import ReactNativeComponent from './ReactNativeComponent';
3734
import {getClosestInstanceFromNode} from './ReactFabricComponentTree';
@@ -42,6 +39,8 @@ import ReactSharedInternals from 'shared/ReactSharedInternals';
4239
import getComponentName from 'shared/getComponentName';
4340
import warningWithoutStack from 'shared/warningWithoutStack';
4441

42+
const {dispatchCommand: fabricDispatchCommand} = nativeFabricUIManager;
43+
4544
const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
4645

4746
function findHostInstance_DEPRECATED(
@@ -162,24 +161,23 @@ const ReactFabric: ReactFabricType = {
162161
findNodeHandle,
163162

164163
dispatchCommand(handle: any, command: string, args: Array<any>) {
165-
if (handle._nativeTag == null) {
164+
const invalid =
165+
handle._nativeTag == null || handle._internalInstanceHandle == null;
166+
167+
if (invalid) {
166168
warningWithoutStack(
167-
handle._nativeTag != null,
169+
!invalid,
168170
"dispatchCommand was called with a ref that isn't a " +
169171
'native component. Use React.forwardRef to get access to the underlying native component',
170172
);
171173
return;
172174
}
173175

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-
}
176+
fabricDispatchCommand(
177+
handle._internalInstanceHandle.stateNode.node,
178+
command,
179+
args,
180+
);
183181
},
184182

185183
render(element: React$Element<any>, containerTag: any, callback: ?Function) {

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,7 @@ const ReactNativeRenderer: ReactNativeType = {
180180
return;
181181
}
182182

183-
if (handle._internalInstanceHandle) {
184-
nativeFabricUIManager.dispatchCommand(
185-
handle._internalInstanceHandle.stateNode.node,
186-
command,
187-
args,
188-
);
189-
} else {
190-
UIManager.dispatchViewManagerCommand(handle._nativeTag, command, args);
191-
}
183+
UIManager.dispatchViewManagerCommand(handle._nativeTag, command, args);
192184
},
193185

194186
render(element: React$Element<any>, containerTag: any, callback: ?Function) {

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

Lines changed: 3 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ let ReactNative;
1616
let UIManager;
1717
let createReactNativeComponentClass;
1818

19-
describe('created with ReactFabric called with ReactNative', () => {
19+
describe('ReactFabric', () => {
2020
beforeEach(() => {
2121
jest.resetModules();
2222
require('react-native/Libraries/ReactPrivate/InitializeNativeFabricUIManager');
@@ -75,86 +75,6 @@ describe('created with ReactFabric called with ReactNative', () => {
7575
});
7676

7777
it('dispatches commands on Fabric nodes with the RN renderer', () => {
78-
nativeFabricUIManager.dispatchCommand.mockClear();
79-
const View = createReactNativeComponentClass('RCTView', () => ({
80-
validAttributes: {title: true},
81-
uiViewClassName: 'RCTView',
82-
}));
83-
84-
let ref = React.createRef();
85-
86-
ReactFabric.render(<View title="bar" ref={ref} />, 11);
87-
expect(nativeFabricUIManager.dispatchCommand).not.toBeCalled();
88-
ReactNative.dispatchCommand(ref.current, 'myCommand', [10, 20]);
89-
expect(nativeFabricUIManager.dispatchCommand).toHaveBeenCalledTimes(1);
90-
expect(nativeFabricUIManager.dispatchCommand).toHaveBeenCalledWith(
91-
expect.any(Object),
92-
'myCommand',
93-
[10, 20],
94-
);
95-
expect(UIManager.dispatchViewManagerCommand).not.toBeCalled();
96-
});
97-
});
98-
99-
describe('created with ReactNative called with ReactFabric', () => {
100-
beforeEach(() => {
101-
jest.resetModules();
102-
require('react-native/Libraries/ReactPrivate/InitializeNativeFabricUIManager');
103-
ReactFabric = require('react-native-renderer/fabric');
104-
jest.resetModules();
105-
UIManager = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
106-
.UIManager;
107-
jest.mock('shared/ReactFeatureFlags', () =>
108-
require('shared/forks/ReactFeatureFlags.native-oss'),
109-
);
110-
ReactNative = require('react-native-renderer');
111-
112-
React = require('react');
113-
createReactNativeComponentClass = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
114-
.ReactNativeViewConfigRegistry.register;
115-
});
116-
117-
it('find Paper instances with the Fabric renderer', () => {
118-
const View = createReactNativeComponentClass('RCTView', () => ({
119-
validAttributes: {title: true},
120-
uiViewClassName: 'RCTView',
121-
}));
122-
123-
let ref = React.createRef();
124-
125-
class Component extends React.Component {
126-
render() {
127-
return <View title="foo" />;
128-
}
129-
}
130-
131-
ReactNative.render(<Component ref={ref} />, 11);
132-
133-
let instance = ReactFabric.findHostInstance_DEPRECATED(ref.current);
134-
expect(instance._nativeTag).toBe(3);
135-
});
136-
137-
it('find Paper nodes with the Fabric renderer', () => {
138-
const View = createReactNativeComponentClass('RCTView', () => ({
139-
validAttributes: {title: true},
140-
uiViewClassName: 'RCTView',
141-
}));
142-
143-
let ref = React.createRef();
144-
145-
class Component extends React.Component {
146-
render() {
147-
return <View title="foo" />;
148-
}
149-
}
150-
151-
ReactNative.render(<Component ref={ref} />, 11);
152-
153-
let handle = ReactFabric.findNodeHandle(ref.current);
154-
expect(handle).toBe(3);
155-
});
156-
157-
it('dispatches commands on Paper nodes with the Fabric renderer', () => {
15878
UIManager.dispatchViewManagerCommand.mockReset();
15979
const View = createReactNativeComponentClass('RCTView', () => ({
16080
validAttributes: {title: true},
@@ -163,16 +83,14 @@ describe('created with ReactNative called with ReactFabric', () => {
16383

16484
let ref = React.createRef();
16585

166-
ReactNative.render(<View title="bar" ref={ref} />, 11);
86+
ReactFabric.render(<View title="bar" ref={ref} />, 11);
16787
expect(UIManager.dispatchViewManagerCommand).not.toBeCalled();
168-
ReactFabric.dispatchCommand(ref.current, 'myCommand', [10, 20]);
88+
ReactNative.dispatchCommand(ref.current, 'myCommand', [10, 20]);
16989
expect(UIManager.dispatchViewManagerCommand).toHaveBeenCalledTimes(1);
17090
expect(UIManager.dispatchViewManagerCommand).toHaveBeenCalledWith(
17191
expect.any(Number),
17292
'myCommand',
17393
[10, 20],
17494
);
175-
176-
expect(nativeFabricUIManager.dispatchCommand).not.toBeCalled();
17795
});
17896
});

0 commit comments

Comments
 (0)