Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/react-native-renderer/src/ReactFabric.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import ReactFabricRenderer from './ReactFabricRenderer';
import ReactNativePropRegistry from './ReactNativePropRegistry';
import {getInspectorDataForViewTag} from './ReactNativeFiberInspector';
import createReactNativeComponentClass from './createReactNativeComponentClass';
import {injectFindHostInstanceFabric} from './findNodeHandle';
import {injectFindHostInstance} from './findNodeHandle';
import findNumericNodeHandle from './findNumericNodeHandle';
import takeSnapshot from './takeSnapshot';

injectFindHostInstanceFabric(ReactFabricRenderer.findHostInstance);
injectFindHostInstance(ReactFabricRenderer.findHostInstance);

ReactGenericBatching.injection.injectRenderer(ReactFabricRenderer);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
* @jest-environment node
*/

'use strict';

let React;
let ReactFabric;
let ReactNative;
let createReactNativeComponentClass;

describe('ReactFabric', () => {
beforeEach(() => {
jest.resetModules();
ReactNative = require('react-native-renderer');
jest.resetModules();
jest.mock('shared/ReactFeatureFlags', () =>
require('shared/forks/ReactFeatureFlags.native-fabric'),
);

React = require('react');
ReactFabric = require('react-native-renderer/fabric');
createReactNativeComponentClass = require('../createReactNativeComponentClass')
.default;
});

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

let ref = React.createRef();

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

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

let handle = ReactNative.findNodeHandle(ref.current);
expect(handle).toBe(2);
});
});
26 changes: 1 addition & 25 deletions packages/react-native-renderer/src/findNodeHandle.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,14 @@ import getComponentName from 'shared/getComponentName';
import invariant from 'fbjs/lib/invariant';
import warning from 'fbjs/lib/warning';

// TODO: Share this module between Fabric and React Native renderers
// so that both can be used in the same tree.

let findHostInstance = function(fiber: Fiber): any {
return null;
};

let findHostInstanceFabric = function(fiber: Fiber): any {
return null;
};

export function injectFindHostInstance(impl: (fiber: Fiber) => any) {
findHostInstance = impl;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do these not overwrite each other if called twice?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They're in separate bundles but I'm going to do a follow up that doesn't use injection and uses instantiation instead.

}

export function injectFindHostInstanceFabric(impl: (fiber: Fiber) => any) {
findHostInstanceFabric = impl;
}

/**
* ReactNative vs ReactWeb
* -----------------------
Expand Down Expand Up @@ -98,24 +87,11 @@ function findNodeHandle(componentOrHandle: any): any {
// ReactInstanceMap.get here will always succeed for mounted components
const internalInstance: Fiber = ReactInstanceMap.get(component);
if (internalInstance) {
return (
findHostInstance(internalInstance) ||
findHostInstanceFabric(internalInstance)
);
return findHostInstance(internalInstance);
} else {
if (component) {
return component;
} else {
invariant(
// Native
(typeof component === 'object' && '_nativeTag' in component) ||
// Composite
(component.render != null && typeof component.render === 'function'),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is always falsy according to the branch above. So never can pass. This must throw?

Copy link
Collaborator

Choose a reason for hiding this comment

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

lol. brb going to add a function to Number.prototype.render

'findNodeHandle(...): Argument is not a component ' +
'(type: %s, keys: %s)',
typeof component,
Object.keys(component),
);
invariant(
false,
'findNodeHandle(...): Unable to find node handle for unmounted ' +
Expand Down
3 changes: 3 additions & 0 deletions packages/react-native-renderer/src/findNumericNodeHandle.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ export default function findNumericNodeHandleFiber(
if (instance == null || typeof instance === 'number') {
return instance;
}
if (instance.canonical) {
return instance.canonical._nativeTag;
}
return instance._nativeTag;
}