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

Pass instance handle to all Fabric clone methods #12824

Merged
merged 1 commit into from
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 28 additions & 13 deletions packages/react-native-renderer/src/ReactFabricHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,17 @@ import invariant from 'fbjs/lib/invariant';

// Modules provided by RN:
import TextInputState from 'TextInputState';
import FabricUIManager from 'FabricUIManager';
import {
createNode,
cloneNode,
cloneNodeWithNewChildren,
cloneNodeWithNewChildrenAndProps,
cloneNodeWithNewProps,
createChildSet,
appendChild,
appendChildToSet,
completeRoot,
} from 'FabricUIManager';
import UIManager from 'UIManager';

// Counter for uniquely identifying views.
Expand Down Expand Up @@ -126,12 +136,12 @@ type TextInstance = {
node: Node,
};

const ReacFabricHostConfig = {
const ReactFabricHostConfig = {
appendInitialChild(
parentInstance: Instance,
child: Instance | TextInstance,
): void {
FabricUIManager.appendChild(parentInstance.node, child.node);
appendChild(parentInstance.node, child.node);
},

createInstance(
Expand Down Expand Up @@ -164,7 +174,7 @@ const ReacFabricHostConfig = {
viewConfig.validAttributes,
);

const node = FabricUIManager.createNode(
const node = createNode(
tag, // reactTag
viewConfig.uiViewClassName, // viewName
rootContainerInstance, // rootTag
Expand Down Expand Up @@ -194,7 +204,7 @@ const ReacFabricHostConfig = {
const tag = nextReactTag;
nextReactTag += 2;

const node = FabricUIManager.createNode(
const node = createNode(
tag, // reactTag
'RCTRawText', // viewName
rootContainerInstance, // rootTag
Expand Down Expand Up @@ -307,18 +317,23 @@ const ReacFabricHostConfig = {
let clone;
if (keepChildren) {
if (updatePayload !== null) {
clone = FabricUIManager.cloneNodeWithNewProps(node, updatePayload);
clone = cloneNodeWithNewProps(
node,
updatePayload,
internalInstanceHandle,
);
} else {
clone = FabricUIManager.cloneNode(node);
clone = cloneNode(node, internalInstanceHandle);
}
} else {
if (updatePayload !== null) {
clone = FabricUIManager.cloneNodeWithNewChildrenAndProps(
clone = cloneNodeWithNewChildrenAndProps(
node,
updatePayload,
internalInstanceHandle,
);
} else {
clone = FabricUIManager.cloneNodeWithNewChildren(node);
clone = cloneNodeWithNewChildren(node, internalInstanceHandle);
}
}
return {
Expand All @@ -328,21 +343,21 @@ const ReacFabricHostConfig = {
},

createContainerChildSet(container: Container): ChildSet {
return FabricUIManager.createChildSet(container);
return createChildSet(container);
},

appendChildToContainerChildSet(
childSet: ChildSet,
child: Instance | TextInstance,
): void {
FabricUIManager.appendChildToSet(childSet, child.node);
appendChildToSet(childSet, child.node);
},

finalizeContainerChildren(
container: Container,
newChildren: ChildSet,
): void {
FabricUIManager.completeRoot(container, newChildren);
completeRoot(container, newChildren);
},

replaceContainerChildren(
Expand All @@ -352,4 +367,4 @@ const ReacFabricHostConfig = {
},
};

export default ReacFabricHostConfig;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha oops

export default ReactFabricHostConfig;
14 changes: 11 additions & 3 deletions packages/react-native-renderer/src/__mocks__/FabricUIManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,18 @@ const RCTFabricUIManager = {
children: [],
};
}),
cloneNode: jest.fn(function cloneNode(node) {
cloneNode: jest.fn(function cloneNode(node, instanceHandle) {
return {
reactTag: node.reactTag,
viewName: node.viewName,
props: node.props,
children: node.children,
};
}),
cloneNodeWithNewChildren: jest.fn(function cloneNodeWithNewChildren(node) {
cloneNodeWithNewChildren: jest.fn(function cloneNodeWithNewChildren(
node,
instanceHandle,
) {
return {
reactTag: node.reactTag,
viewName: node.viewName,
Expand All @@ -84,6 +87,7 @@ const RCTFabricUIManager = {
cloneNodeWithNewProps: jest.fn(function cloneNodeWithNewProps(
node,
newPropsDiff,
instanceHandle,
) {
return {
reactTag: node.reactTag,
Expand All @@ -93,7 +97,11 @@ const RCTFabricUIManager = {
};
}),
cloneNodeWithNewChildrenAndProps: jest.fn(
function cloneNodeWithNewChildrenAndProps(node, newPropsDiff) {
function cloneNodeWithNewChildrenAndProps(
node,
newPropsDiff,
instanceHandle,
) {
return {
reactTag: node.reactTag,
viewName: node.viewName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ describe('ReactFabric', () => {
ReactFabric.render(<View foo="bar" />, 11);

expect(FabricUIManager.createNode.mock.calls.length).toBe(1);
expect(FabricUIManager.cloneNodeWithNewProps).toBeCalledWith(firstNode, {
expect(FabricUIManager.cloneNodeWithNewProps.mock.calls.length).toBe(1);
expect(FabricUIManager.cloneNodeWithNewProps.mock.calls[0][0]).toBe(
firstNode,
);
expect(FabricUIManager.cloneNodeWithNewProps.mock.calls[0][1]).toEqual({
foo: 'bar',
});
});
Expand Down
9 changes: 7 additions & 2 deletions scripts/flow/react-native-host-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,20 @@ declare module 'FabricUIManager' {
props: ?Object,
instanceHandle: Object,
): Object;
declare function cloneNode(node: Object): Object;
declare function cloneNodeWithNewChildren(node: Object): Object;
declare function cloneNode(node: Object, instanceHandle: Object): Object;
declare function cloneNodeWithNewChildren(
node: Object,
instanceHandle: Object,
): Object;
declare function cloneNodeWithNewProps(
node: Object,
newProps: ?Object,
instanceHandle: Object,
): Object;
declare function cloneNodeWithNewChildrenAndProps(
node: Object,
newProps: ?Object,
instanceHandle: Object,
): Object;
declare function appendChild(node: Object, childNode: Object): void;

Expand Down