Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring ReactFabricHostComponent back to react-native #36570

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ module.exports = {
testPathIgnorePatterns: [
'/node_modules/',
'<rootDir>/packages/react-native/template',
'<rootDir>/packages/react-native/Libraries/Renderer',
'<rootDir>/packages/react-native/Libraries/Renderer/implementations',
'<rootDir>/packages/react-native/Libraries/Renderer/shims',
'<rootDir>/packages/rn-tester/e2e',
],
transformIgnorePatterns: ['node_modules/(?!@react-native/)'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ import type {
MeasureInWindowOnSuccessCallback,
MeasureLayoutOnSuccessCallback,
MeasureOnSuccessCallback,
Node,
} from '../Renderer/shims/ReactNativeTypes';
import type {RootTag} from '../Types/RootTagTypes';

// TODO: type these properly.
export opaque type Node = {...};
type NodeSet = Array<Node>;
type NodeProps = {...};
type InstanceHandle = {...};
export type NodeSet = Array<Node>;
export type NodeProps = {...};
export type InstanceHandle = {...};
export type Spec = {|
+createNode: (
reactTag: number,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/

import type {
LayoutAnimationConfig,
MeasureInWindowOnSuccessCallback,
MeasureLayoutOnSuccessCallback,
MeasureOnSuccessCallback,
Node,
} from '../../Renderer/shims/ReactNativeTypes';
import type {RootTag} from '../../Types/RootTagTypes';
import type {
InstanceHandle,
NodeProps,
NodeSet,
Spec as FabricUIManager,
} from '../FabricUIManager';

type NodeMock = {
reactTag: number,
rootTag: RootTag,
props: NodeProps,
instanceHandle: InstanceHandle,
children: NodeSet,
};

function fromNode(node: Node): NodeMock {
// $FlowExpectedError[incompatible-return]
return node;
}

function toNode(node: NodeMock): Node {
// $FlowExpectedError[incompatible-return]
return node;
}

const FabricUIManagerMock: FabricUIManager = {
createNode: jest.fn(
(
reactTag: number,
viewName: string,
rootTag: RootTag,
props: NodeProps,
instanceHandle: InstanceHandle,
): Node => {
return toNode({
reactTag,
rootTag,
props,
instanceHandle,
children: [],
});
},
),
cloneNode: jest.fn((node: Node): Node => {
return toNode({...fromNode(node)});
}),
cloneNodeWithNewChildren: jest.fn((node: Node): Node => {
return toNode({...fromNode(node), children: []});
}),
cloneNodeWithNewProps: jest.fn((node: Node, newProps: NodeProps): Node => {
return toNode({...fromNode(node), props: newProps});
}),
cloneNodeWithNewChildrenAndProps: jest.fn(
(node: Node, newProps: NodeProps): Node => {
return toNode({...fromNode(node), children: [], props: newProps});
},
),
createChildSet: jest.fn((rootTag: RootTag): NodeSet => {
return [];
}),
appendChild: jest.fn((parentNode: Node, child: Node): Node => {
return toNode({
...fromNode(parentNode),
children: fromNode(parentNode).children.concat(child),
});
}),
appendChildToSet: jest.fn((childSet: NodeSet, child: Node): void => {
childSet.push(child);
}),
completeRoot: jest.fn((rootTag: RootTag, childSet: NodeSet): void => {}),
measure: jest.fn((node: Node, callback: MeasureOnSuccessCallback): void => {
callback(10, 10, 100, 100, 0, 0);
}),
measureInWindow: jest.fn(
(node: Node, callback: MeasureInWindowOnSuccessCallback): void => {
callback(10, 10, 100, 100);
},
),
measureLayout: jest.fn(
(
node: Node,
relativeNode: Node,
onFail: () => void,
onSuccess: MeasureLayoutOnSuccessCallback,
): void => {
onSuccess(1, 1, 100, 100);
},
),
configureNextLayoutAnimation: jest.fn(
(
config: LayoutAnimationConfig,
callback: () => void, // check what is returned here
errorCallback: () => void,
): void => {},
),
sendAccessibilityEvent: jest.fn((node: Node, eventType: string): void => {}),
findShadowNodeByTag_DEPRECATED: jest.fn((reactTag: number): ?Node => {}),
getBoundingClientRect: jest.fn(
(
node: Node,
): [
/* x:*/ number,
/* y:*/ number,
/* width:*/ number,
/* height:*/ number,
] => {
return [1, 1, 100, 100];
},
),
setNativeProps: jest.fn((node: Node, newProps: NodeProps): void => {}),
dispatchCommand: jest.fn(
(node: Node, commandName: string, args: Array<mixed>): void => {},
),
};

global.nativeFabricUIManager = FabricUIManagerMock;

export function getFabricUIManager(): ?FabricUIManager {
return FabricUIManagerMock;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@ import typeof ReactFiberErrorDialog from '../Core/ReactFiberErrorDialog';
import typeof RCTEventEmitter from '../EventEmitter/RCTEventEmitter';
import typeof CustomEvent from '../Events/CustomEvent';
import typeof UIManager from '../ReactNative/UIManager';
import typeof {
createPublicInstance,
getNativeTagFromPublicInstance,
getNodeFromPublicInstance,
} from '../Renderer/public/ReactFabricPublicInstance';
import typeof {
create as createAttributePayload,
diff as diffAttributePayloads,
} from '../Renderer/public/ReactNativeAttributePayload';
import typeof ReactNativeViewConfigRegistry from '../Renderer/shims/ReactNativeViewConfigRegistry';
import typeof flattenStyle from '../StyleSheet/flattenStyle';
import type {DangerouslyImpreciseStyleProp} from '../StyleSheet/StyleSheet';
import typeof deepFreezeAndThrowOnMutationInDev from '../Utilities/deepFreezeAndThrowOnMutationInDev';
import typeof deepDiffer from '../Utilities/differ/deepDiffer';
import typeof Platform from '../Utilities/Platform';

import {type DangerouslyImpreciseStyleProp} from '../StyleSheet/StyleSheet';

// flowlint unsafe-getters-setters:off
module.exports = {
get BatchedBridge(): BatchedBridge {
Expand All @@ -48,6 +56,7 @@ module.exports = {
get UIManager(): UIManager {
return require('../ReactNative/UIManager');
},
// TODO: Remove when React has migrated to `createAttributePayload` and `diffAttributePayloads`
get deepDiffer(): deepDiffer {
return require('../Utilities/differ/deepDiffer');
},
Expand All @@ -56,6 +65,7 @@ module.exports = {
> {
return require('../Utilities/deepFreezeAndThrowOnMutationInDev');
},
// TODO: Remove when React has migrated to `createAttributePayload` and `diffAttributePayloads`
get flattenStyle(): flattenStyle<DangerouslyImpreciseStyleProp> {
// $FlowFixMe[underconstrained-implicit-instantiation]
return require('../StyleSheet/flattenStyle');
Expand All @@ -72,4 +82,22 @@ module.exports = {
get CustomEvent(): CustomEvent {
return require('../Events/CustomEvent').default;
},
get createAttributePayload(): createAttributePayload {
return require('../Renderer/public/ReactNativeAttributePayload').create;
},
get diffAttributePayloads(): diffAttributePayloads {
return require('../Renderer/public/ReactNativeAttributePayload').diff;
},
get createPublicInstance(): createPublicInstance {
return require('../Renderer/public/ReactFabricPublicInstance')
.createPublicInstance;
},
get getNativeTagFromPublicInstance(): getNativeTagFromPublicInstance {
return require('../Renderer/public/ReactFabricPublicInstance')
.getNativeTagFromPublicInstance;
},
get getNodeFromPublicInstance(): getNodeFromPublicInstance {
return require('../Renderer/public/ReactFabricPublicInstance')
.getNodeFromPublicInstance;
},
};
Loading