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

Move definition and instantiation of public instances for Fabric from React to React Native #26418

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
10 changes: 4 additions & 6 deletions packages/react-native-renderer/src/ReactFabricHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
*/

import type {TouchedViewDataAtPoint, ViewConfig} from './ReactNativeTypes';
import {
createPublicInstance,
type ReactFabricHostComponent,
} from './ReactFabricPublicInstance';
import {create, diff} from './ReactNativeAttributePayload';
import {dispatchEvent} from './ReactFabricEventEmitter';
import {
Expand All @@ -23,6 +19,8 @@ import {
import {
ReactNativeViewConfigRegistry,
deepFreezeAndThrowOnMutationInDev,
createPublicInstance,
type PublicInstance as FabricPublicInstance,
} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';

const {
Expand Down Expand Up @@ -62,12 +60,12 @@ export type Instance = {
// Reference to the React handle (the fiber)
internalInstanceHandle: Object,
// Exposed through refs.
publicInstance: ReactFabricHostComponent,
publicInstance: PublicInstance,
},
};
export type TextInstance = {node: Node, ...};
export type HydratableInstance = Instance | TextInstance;
export type PublicInstance = ReactFabricHostComponent;
export type PublicInstance = FabricPublicInstance;
export type Container = number;
export type ChildSet = Object;
export type HostContext = $ReadOnly<{
Expand Down
153 changes: 0 additions & 153 deletions packages/react-native-renderer/src/ReactFabricPublicInstance.js

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import {
import getComponentNameFromType from 'shared/getComponentNameFromType';
import {HostComponent} from 'react-reconciler/src/ReactWorkTags';
// Module provided by RN:
import {UIManager} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
import {
UIManager,
getNodeFromPublicInstance,
} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
import {enableGetInspectorDataForInstanceInProduction} from 'shared/ReactFeatureFlags';
import {getClosestInstanceFromNode} from './ReactNativeComponentTree';
import {getNodeFromPublicInstance} from './ReactFabricPublicInstanceUtils';
import {getNodeFromInternalInstanceHandle} from './ReactNativePublicCompat';

const emptyObject = {};
Expand Down
11 changes: 4 additions & 7 deletions packages/react-native-renderer/src/ReactNativePublicCompat.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import type {ElementRef, ElementType} from 'react';
import {
UIManager,
legacySendAccessibilityEvent,
getNodeFromPublicInstance,
getNativeTagFromPublicInstance,
} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';

import {
Expand All @@ -23,11 +25,6 @@ import {
import ReactSharedInternals from 'shared/ReactSharedInternals';
import getComponentNameFromType from 'shared/getComponentNameFromType';

import {
getNodeFromPublicInstance,
getNativeTagFromPublicInstance,
} from './ReactFabricPublicInstanceUtils';

const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;

export function findHostInstance_DEPRECATED<TElementType: ElementType>(
Expand Down Expand Up @@ -83,6 +80,7 @@ export function findHostInstance_DEPRECATED<TElementType: ElementType>(

// findHostInstance handles legacy vs. Fabric differences correctly
// $FlowFixMe[incompatible-exact] we need to fix the definition of `HostComponent` to use NativeMethods as an interface, not as a type.
// $FlowFixMe[incompatible-return]
return hostInstance;
}

Expand Down Expand Up @@ -147,9 +145,8 @@ export function findNodeHandle(componentOrHandle: any): ?number {
return hostInstance;
}

// $FlowFixMe[prop-missing] For compatibility with legacy renderer instances
// $FlowFixMe[incompatible-type] For compatibility with legacy renderer instances
if (hostInstance._nativeTag != null) {
// $FlowFixMe[incompatible-return]
return hostInstance._nativeTag;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* @flow strict-local
*/

export opaque type PublicInstance = mixed;

module.exports = {
get BatchedBridge() {
return require('./BatchedBridge.js');
Expand Down Expand Up @@ -44,4 +46,13 @@ module.exports = {
get RawEventEmitter() {
return require('./RawEventEmitter').default;
},
get getNativeTagFromPublicInstance() {
return require('./getNativeTagFromPublicInstance').default;
},
get getNodeFromPublicInstance() {
return require('./getNodeFromPublicInstance').default;
},
get createPublicInstance() {
return require('./createPublicInstance').default;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* 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
*/

import type {PublicInstance} from './ReactNativePrivateInterface';

export default function createPublicInstance(
tag: number,
viewConfig: mixed,
internalInstanceHandle: mixed,
): PublicInstance {
return {
__nativeTag: tag,
__internalInstanceHandle: internalInstanceHandle,
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* 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
*/

import type {PublicInstance} from './ReactNativePrivateInterface';

export default function getNativeTagFromPublicInstance(
publicInstance: PublicInstance,
) {
return publicInstance.__nativeTag;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* 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
*/

import type {PublicInstance} from './ReactNativePrivateInterface';

import {getNodeFromInternalInstanceHandle} from '../../../../ReactNativePublicCompat';

export default function getNodeFromPublicInstance(
publicInstance: PublicInstance,
) {
return getNodeFromInternalInstanceHandle(
publicInstance.__internalInstanceHandle,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ describe('ReactFabric', () => {
require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
.ReactNativeViewConfigRegistry.register;
getNativeTagFromPublicInstance =
require('../ReactFabricPublicInstanceUtils').getNativeTagFromPublicInstance;
require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface').getNativeTagFromPublicInstance;
getNodeFromPublicInstance =
require('../ReactFabricPublicInstanceUtils').getNodeFromPublicInstance;
require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface').getNodeFromPublicInstance;

act = require('internal-test-utils').act;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('created with ReactFabric called with ReactNative', () => {
require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
.ReactNativeViewConfigRegistry.register;
getNativeTagFromPublicInstance =
require('../ReactFabricPublicInstanceUtils').getNativeTagFromPublicInstance;
require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface').getNativeTagFromPublicInstance;
});

it('find Fabric instances with the RN renderer', () => {
Expand Down
Loading