Skip to content
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
15 changes: 2 additions & 13 deletions packages/react-native-fantom/src/__tests__/Fantom-itest.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,11 @@ function getActualViewportDimensions(root: Root): {
viewportWidth: number,
viewportHeight: number,
} {
let maybeNode;

Fantom.runTask(() => {
root.render(
<View
style={{width: '100%', height: '100%'}}
ref={node => {
maybeNode = node;
}}
/>,
);
root.render(<View />);
});

const node = ensureInstance(maybeNode, ReactNativeElement);

const rect = node.getBoundingClientRect();
const rect = root.document.documentElement.getBoundingClientRect();
return {
viewportWidth: rect.width,
viewportHeight: rect.height,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,32 @@ describe('ReactNativeDocument', () => {
expect(document.textContent).toBe(null);
});

it('provides a documentElement node that behaves like a regular element', () => {
let lastNode;

const root = Fantom.createRoot({viewportWidth: 200, viewportHeight: 100});
Fantom.runTask(() => {
root.render(
<View
ref={node => {
lastNode = node;
}}
/>,
);
});

const element = ensureInstance(lastNode, ReactNativeElement);
const document = ensureInstance(element.ownerDocument, ReactNativeDocument);

const {x, y, width, height} =
document.documentElement.getBoundingClientRect();

expect(x).toBe(0);
expect(y).toBe(0);
expect(width).toBe(200);
expect(height).toBe(100);
});

it('implements compareDocumentPosition correctly', () => {
let lastNode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ export function getNativeElementReference(
// $FlowExpectedError[incompatible-cast] We know ReadOnlyElement instances provide InternalInstanceHandle
const instanceHandle = getInstanceHandle(node) as InternalInstanceHandle;

if (isReactNativeDocumentElementInstanceHandle(instanceHandle)) {
return getNativeElementReferenceFromReactNativeDocumentElementInstanceHandle(
instanceHandle,
);
}

// $FlowExpectedError[incompatible-return]
return getRendererProxy().getNodeFromInternalInstanceHandle(instanceHandle);
}
Expand Down