@samitouri / QOS-React-2 / commits / d0fc0ba0a6

Revert "Dispatch commands to both UIManagers from both renderers (#17211)" (#17232)

This reverts commit 8eee0eb01ce3ead0f51ade75fdcf062a748d57a7.

Eli White committed Oct 30, 2019 at 18:03 UTC d0fc0ba0a688950b8ab24a89f14888a19efa2444
3 files changed +16 -108
packages/react-native-renderer/src/ReactFabric.js
+12 -14
@@ -29,9 +29,6 @@ import {createPortal} from 'shared/ReactPortal';
29 import {setBatchingImplementation} from 'legacy-events/ReactGenericBatching';
30 import ReactVersion from 'shared/ReactVersion';
31
32 -// Module provided by RN:
33 -import {UIManager} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
34 -
32 import NativeMethodsMixin from './NativeMethodsMixin';
33 import ReactNativeComponent from './ReactNativeComponent';
34 import {getClosestInstanceFromNode} from './ReactFabricComponentTree';
@@ -42,6 +39,8 @@ import ReactSharedInternals from 'shared/ReactSharedInternals';
39 import getComponentName from 'shared/getComponentName';
40 import warningWithoutStack from 'shared/warningWithoutStack';
41
42 +const {dispatchCommand: fabricDispatchCommand} = nativeFabricUIManager;
43 +
44 const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
45
46 function findHostInstance_DEPRECATED(
@@ -162,24 +161,23 @@ const ReactFabric: ReactFabricType = {
161 findNodeHandle,
162
163 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) {
168 warningWithoutStack(
167 - handle._nativeTag != null,
169 + !invalid,
170 "dispatchCommand was called with a ref that isn't a " +
171 'native component. Use React.forwardRef to get access to the underlying native component',
172 );
173 return;
174 }
175
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 + );
181 },
182
183 render(element: React$Element<any>, containerTag: any, callback: ?Function) {
packages/react-native-renderer/src/ReactNativeRenderer.js
+1 -9
@@ -180,15 +180,7 @@ const ReactNativeRenderer: ReactNativeType = {
180 return;
181 }
182
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);
184 },
185
186 render(element: React$Element<any>, containerTag: any, callback: ?Function) {
packages/react-native-renderer/src/__tests__/ReactFabricAndNative-test.internal.js
+3 -85
@@ -16,7 +16,7 @@ let ReactNative;
16 let UIManager;
17 let createReactNativeComponentClass;
18
19 -describe('created with ReactFabric called with ReactNative', () => {
19 +describe('ReactFabric', () => {
20 beforeEach(() => {
21 jest.resetModules();
22 require('react-native/Libraries/ReactPrivate/InitializeNativeFabricUIManager');
@@ -75,86 +75,6 @@ describe('created with ReactFabric called with ReactNative', () => {
75 });
76
77 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', () => {
78 UIManager.dispatchViewManagerCommand.mockReset();
79 const View = createReactNativeComponentClass('RCTView', () => ({
80 validAttributes: {title: true},
@@ -163,16 +83,14 @@ describe('created with ReactNative called with ReactFabric', () => {
83
84 let ref = React.createRef();
85
166 - ReactNative.render(<View title="bar" ref={ref} />, 11);
86 + ReactFabric.render(<View title="bar" ref={ref} />, 11);
87 expect(UIManager.dispatchViewManagerCommand).not.toBeCalled();
168 - ReactFabric.dispatchCommand(ref.current, 'myCommand', [10, 20]);
88 + ReactNative.dispatchCommand(ref.current, 'myCommand', [10, 20]);
89 expect(UIManager.dispatchViewManagerCommand).toHaveBeenCalledTimes(1);
90 expect(UIManager.dispatchViewManagerCommand).toHaveBeenCalledWith(
91 expect.any(Number),
92 'myCommand',
93 [10, 20],
94 );
175 -
176 - expect(nativeFabricUIManager.dispatchCommand).not.toBeCalled();
95 });
96 });