mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
* [react-native] Use path-based imports instead of Haste for the RN renderer To move React Native to standard path-based imports instead of Haste, the RN renderer that is generated from the code in this repo needs to use path-based imports as well since the generated code is vendored by RN. This commit makes it so the interface between the generated renderers and RN does not rely on Haste and instead uses a private interface explicitly defined by RN. This inverts control of the abstraction so that RN decides the internals to export rather than React deciding what to import. On RN's side, a new module named `react-native/Libraries/ReactPrivate/ReactNativePrivateInterface` explicitly exports the modules used by the renderers in this repo. (There is also a private module for InitializeCore so that we can import it just for the side effects.) On React's side, the various renderer modules access RN internals through the explicit private interface. The Rollup configuration becomes slimmer since the only external package is now `react-native`, and the individual modules are instead listed out in `ReactNativePrivateInterface`. Task description: https://github.com/facebook/react-native/issues/24770 Sister RN PR (needs to land before this one): https://github.com/facebook/react-native/pull/24782 Test Plan: Ran unit tests and Flow in this repo. Generated the renderers and manually copied them over to the RN repo. Ran the RN tests and launched the RNTester app. * Access natively defined "nativeFabricUIManager" instead of importing it Some places in the Fabric renderers access `nativeFabricUIManager` (a natively defined global) instead of importing UIManager. While this is coupling across repos that depends on the timing of events, it is necessary until we have a way to defer top-level imports to run after `nativeFabricUIManager` is defined. So for consistency we use `nativeFabricUIManager` everywhere (see the comment in https://github.com/facebook/react/pull/15604#pullrequestreview-236842223 for more context).
160 lines
4.9 KiB
JavaScript
160 lines
4.9 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
*/
|
|
|
|
/* eslint-disable */
|
|
|
|
import type {
|
|
MeasureOnSuccessCallback,
|
|
MeasureInWindowOnSuccessCallback,
|
|
MeasureLayoutOnSuccessCallback,
|
|
ReactNativeBaseComponentViewConfig,
|
|
ViewConfigGetter,
|
|
} from 'react-native-renderer/src/ReactNativeTypes';
|
|
import type {RNTopLevelEventType} from 'events/TopLevelEventTypes';
|
|
|
|
declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface' {
|
|
declare export function deepDiffer(one: any, two: any): boolean;
|
|
declare export function deepFreezeAndThrowOnMutationInDev<T>(obj: T): T;
|
|
declare export function flattenStyle(style: any): any;
|
|
declare export var RCTEventEmitter: {
|
|
register: (eventEmitter: mixed) => void,
|
|
};
|
|
declare export var TextInputState: {
|
|
blurTextInput: (object: any) => void,
|
|
focusTextInput: (object: any) => void,
|
|
};
|
|
declare export var ExceptionsManager: {
|
|
handleException: (error: Error, isFatal: boolean) => void,
|
|
};
|
|
declare export var Platform: {
|
|
OS: string,
|
|
};
|
|
declare export var UIManager: {
|
|
customBubblingEventTypes: Object,
|
|
customDirectEventTypes: Object,
|
|
createView: (
|
|
reactTag: number,
|
|
viewName: string,
|
|
rootTag: number,
|
|
props: ?Object,
|
|
) => void,
|
|
manageChildren: (
|
|
containerTag: number,
|
|
moveFromIndices: Array<number>,
|
|
moveToIndices: Array<number>,
|
|
addChildReactTags: Array<number>,
|
|
addAtIndices: Array<number>,
|
|
removeAtIndices: Array<number>,
|
|
) => void,
|
|
measure: (hostComponent: mixed, callback: Function) => void,
|
|
measureInWindow: (nativeTag: ?number, callback: Function) => void,
|
|
measureLayout: (
|
|
nativeTag: mixed,
|
|
nativeNode: number,
|
|
onFail: Function,
|
|
onSuccess: Function,
|
|
) => void,
|
|
removeRootView: (containerTag: number) => void,
|
|
removeSubviewsFromContainerWithID: (containerId: number) => void,
|
|
replaceExistingNonRootView: () => void,
|
|
setChildren: (containerTag: number, reactTags: Array<number>) => void,
|
|
updateView: (reactTag: number, viewName: string, props: ?Object) => void,
|
|
__takeSnapshot: (
|
|
view?: 'window' | Element<any> | number,
|
|
options?: {
|
|
width?: number,
|
|
height?: number,
|
|
format?: 'png' | 'jpeg',
|
|
quality?: number,
|
|
},
|
|
) => Promise<any>,
|
|
setJSResponder: (reactTag: number, blockNativeResponder: boolean) => void,
|
|
clearJSResponder: () => void,
|
|
};
|
|
declare export var BatchedBridge: {
|
|
registerCallableModule: (name: string, module: Object) => void,
|
|
};
|
|
declare export var ReactNativeViewConfigRegistry: {
|
|
customBubblingEventTypes: Object,
|
|
customDirectEventTypes: Object,
|
|
eventTypes: Object,
|
|
|
|
register: (name: string, callback: ViewConfigGetter) => string,
|
|
get: (name: string) => ReactNativeBaseComponentViewConfig,
|
|
};
|
|
}
|
|
|
|
declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInitializeCore' {
|
|
}
|
|
|
|
// This is needed for a short term solution.
|
|
// See https://github.com/facebook/react/pull/15490 for more info
|
|
declare var nativeFabricUIManager: {
|
|
createNode: (
|
|
reactTag: number,
|
|
viewName: string,
|
|
rootTag: number,
|
|
props: ?Object,
|
|
eventTarget: Object,
|
|
) => Object,
|
|
cloneNode: (node: Object) => Object,
|
|
cloneNodeWithNewChildren: (node: Object) => Object,
|
|
cloneNodeWithNewProps: (node: Object, newProps: ?Object) => Object,
|
|
cloneNodeWithNewChildrenAndProps: (node: Object, newProps: ?Object) => Object,
|
|
appendChild: (node: Object, childNode: Object) => void,
|
|
|
|
createChildSet: (rootTag: number) => Object,
|
|
appendChildToSet: (childSet: Object, childNode: Object) => void,
|
|
completeRoot: (rootTag: number, childSet: Object) => void,
|
|
registerEventHandler: (
|
|
callback: (
|
|
eventTarget: null | Object,
|
|
type: RNTopLevelEventType,
|
|
payload: Object,
|
|
) => void,
|
|
) => void,
|
|
|
|
measure: (node: Node, callback: MeasureOnSuccessCallback) => void,
|
|
measureInWindow: (
|
|
node: Node,
|
|
callback: MeasureInWindowOnSuccessCallback,
|
|
) => void,
|
|
measureLayout: (
|
|
node: Node,
|
|
relativeNode: Node,
|
|
onFail: () => void,
|
|
onSuccess: MeasureLayoutOnSuccessCallback,
|
|
) => void,
|
|
};
|
|
|
|
declare module 'View' {
|
|
declare module.exports: typeof React$Component;
|
|
}
|
|
|
|
declare module 'RTManager' {
|
|
declare function createNode(
|
|
tag: number,
|
|
classType: string,
|
|
props: ?Object,
|
|
): void;
|
|
|
|
declare function beginUpdates(): void;
|
|
|
|
declare function appendChildToContext(
|
|
contextTag: number,
|
|
childTag: number,
|
|
): void;
|
|
declare function appendChild(parentTag: number, childTag: number): void;
|
|
declare function prependChild(childTag: number, beforeTag: number): void;
|
|
declare function deleteChild(childTag: number): void;
|
|
declare function updateNode(tag: number, props: ?Object): void;
|
|
|
|
declare function completeUpdates(): void;
|
|
}
|