Skip to content

Commit

Permalink
Revert "Dispatch commands to both UIManagers from both renderers (#17211
Browse files Browse the repository at this point in the history
)" (#17232)

This reverts commit 8eee0eb.
  • Loading branch information
elicwhite authored Oct 31, 2019
1 parent bdcdb69 commit d0fc0ba
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 108 deletions.
26 changes: 12 additions & 14 deletions packages/react-native-renderer/src/ReactFabric.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ import {createPortal} from 'shared/ReactPortal';
import {setBatchingImplementation} from 'legacy-events/ReactGenericBatching';
import ReactVersion from 'shared/ReactVersion';

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

import NativeMethodsMixin from './NativeMethodsMixin';
import ReactNativeComponent from './ReactNativeComponent';
import {getClosestInstanceFromNode} from './ReactFabricComponentTree';
Expand All @@ -42,6 +39,8 @@ import ReactSharedInternals from 'shared/ReactSharedInternals';
import getComponentName from 'shared/getComponentName';
import warningWithoutStack from 'shared/warningWithoutStack';

const {dispatchCommand: fabricDispatchCommand} = nativeFabricUIManager;

const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;

function findHostInstance_DEPRECATED(
Expand Down Expand Up @@ -162,24 +161,23 @@ const ReactFabric: ReactFabricType = {
findNodeHandle,

dispatchCommand(handle: any, command: string, args: Array<any>) {
if (handle._nativeTag == null) {
const invalid =
handle._nativeTag == null || handle._internalInstanceHandle == null;

if (invalid) {
warningWithoutStack(
handle._nativeTag != null,
!invalid,
"dispatchCommand was called with a ref that isn't a " +
'native component. Use React.forwardRef to get access to the underlying native component',
);
return;
}

if (handle._internalInstanceHandle) {
nativeFabricUIManager.dispatchCommand(
handle._internalInstanceHandle.stateNode.node,
command,
args,
);
} else {
UIManager.dispatchViewManagerCommand(handle._nativeTag, command, args);
}
fabricDispatchCommand(
handle._internalInstanceHandle.stateNode.node,
command,
args,
);
},

This comment has been minimized.

Copy link
@HondaTypeR

HondaTypeR Oct 31, 2019

GOOD

render(element: React$Element<any>, containerTag: any, callback: ?Function) {
Expand Down
10 changes: 1 addition & 9 deletions packages/react-native-renderer/src/ReactNativeRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,7 @@ const ReactNativeRenderer: ReactNativeType = {
return;
}

if (handle._internalInstanceHandle) {
nativeFabricUIManager.dispatchCommand(
handle._internalInstanceHandle.stateNode.node,
command,
args,
);
} else {
UIManager.dispatchViewManagerCommand(handle._nativeTag, command, args);
}
UIManager.dispatchViewManagerCommand(handle._nativeTag, command, args);
},

render(element: React$Element<any>, containerTag: any, callback: ?Function) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let ReactNative;
let UIManager;
let createReactNativeComponentClass;

describe('created with ReactFabric called with ReactNative', () => {
describe('ReactFabric', () => {
beforeEach(() => {
jest.resetModules();
require('react-native/Libraries/ReactPrivate/InitializeNativeFabricUIManager');
Expand Down Expand Up @@ -75,86 +75,6 @@ describe('created with ReactFabric called with ReactNative', () => {
});

it('dispatches commands on Fabric nodes with the RN renderer', () => {
nativeFabricUIManager.dispatchCommand.mockClear();
const View = createReactNativeComponentClass('RCTView', () => ({
validAttributes: {title: true},
uiViewClassName: 'RCTView',
}));

let ref = React.createRef();

ReactFabric.render(<View title="bar" ref={ref} />, 11);
expect(nativeFabricUIManager.dispatchCommand).not.toBeCalled();
ReactNative.dispatchCommand(ref.current, 'myCommand', [10, 20]);
expect(nativeFabricUIManager.dispatchCommand).toHaveBeenCalledTimes(1);
expect(nativeFabricUIManager.dispatchCommand).toHaveBeenCalledWith(
expect.any(Object),
'myCommand',
[10, 20],
);
expect(UIManager.dispatchViewManagerCommand).not.toBeCalled();
});
});

describe('created with ReactNative called with ReactFabric', () => {
beforeEach(() => {
jest.resetModules();
require('react-native/Libraries/ReactPrivate/InitializeNativeFabricUIManager');
ReactFabric = require('react-native-renderer/fabric');
jest.resetModules();
UIManager = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
.UIManager;
jest.mock('shared/ReactFeatureFlags', () =>
require('shared/forks/ReactFeatureFlags.native-oss'),
);
ReactNative = require('react-native-renderer');

React = require('react');
createReactNativeComponentClass = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
.ReactNativeViewConfigRegistry.register;
});

it('find Paper instances with the Fabric renderer', () => {
const View = createReactNativeComponentClass('RCTView', () => ({
validAttributes: {title: true},
uiViewClassName: 'RCTView',
}));

let ref = React.createRef();

class Component extends React.Component {
render() {
return <View title="foo" />;
}
}

ReactNative.render(<Component ref={ref} />, 11);

let instance = ReactFabric.findHostInstance_DEPRECATED(ref.current);
expect(instance._nativeTag).toBe(3);
});

it('find Paper nodes with the Fabric renderer', () => {
const View = createReactNativeComponentClass('RCTView', () => ({
validAttributes: {title: true},
uiViewClassName: 'RCTView',
}));

let ref = React.createRef();

class Component extends React.Component {
render() {
return <View title="foo" />;
}
}

ReactNative.render(<Component ref={ref} />, 11);

let handle = ReactFabric.findNodeHandle(ref.current);
expect(handle).toBe(3);
});

it('dispatches commands on Paper nodes with the Fabric renderer', () => {
UIManager.dispatchViewManagerCommand.mockReset();
const View = createReactNativeComponentClass('RCTView', () => ({
validAttributes: {title: true},
Expand All @@ -163,16 +83,14 @@ describe('created with ReactNative called with ReactFabric', () => {

let ref = React.createRef();

ReactNative.render(<View title="bar" ref={ref} />, 11);
ReactFabric.render(<View title="bar" ref={ref} />, 11);
expect(UIManager.dispatchViewManagerCommand).not.toBeCalled();
ReactFabric.dispatchCommand(ref.current, 'myCommand', [10, 20]);
ReactNative.dispatchCommand(ref.current, 'myCommand', [10, 20]);
expect(UIManager.dispatchViewManagerCommand).toHaveBeenCalledTimes(1);
expect(UIManager.dispatchViewManagerCommand).toHaveBeenCalledWith(
expect.any(Number),
'myCommand',
[10, 20],
);

expect(nativeFabricUIManager.dispatchCommand).not.toBeCalled();
});
});

0 comments on commit d0fc0ba

Please sign in to comment.