react/scripts/flow/react-native-host-hooks.js
Eli White 1b2159acc3
[React Native] measure calls will now call FabricUIManager (#15324)
* [React Native] Add tests to paper renderer for measure, measureLayout

* [React Native] measure calls will now call FabricUIManager

The Fabric renderer was previously calling the paper UIManager's measure calls and passing the react tag. This PR changes the renderer to now call FabricUIManager passing the node instead.

One of the parts of this that feels more controversial is making NativeMethodsMixin and ReactNative.NativeComponent warn when calling measureLayout in Fabric. As Seb and I decided in https://github.com/facebook/react/pull/15126, it doesn't make sense for a component created with one of these methods to require a native ref but not work the other way around. For example: a.measureLayout(b) might work but b.measureLayout(a) wouldn't. We figure we should keep these consistent and continue migrating things off of NativeMethodsMixin and NativeComponent.

If this becomes problematic for the Fabric rollout then we should revisit this.

* Fixing Flow

* Add FabricUIManager to externals for paper renderer

* import * as FabricUIManager from 'FabricUIManager';

* Update tests

* Shouldn't have removed UIManager import

* Update with the new tests
2019-04-09 15:10:15 -07:00

184 lines
5.1 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 'deepDiffer' {
declare module.exports: (one: any, two: any) => boolean;
}
declare module 'deepFreezeAndThrowOnMutationInDev' {
declare module.exports: <T>(obj: T) => T;
}
declare module 'flattenStyle' {
}
declare module 'InitializeCore' {
}
declare module 'RCTEventEmitter' {
declare function register(mixed): void;
}
declare module 'TextInputState' {
declare function blurTextInput(object: any): void;
declare function focusTextInput(object: any): void;
}
declare module 'ExceptionsManager' {
declare function handleException(error: Error, isFatal: boolean): void;
}
declare module 'Platform' {
declare var OS: string;
}
declare module 'UIManager' {
declare var customBubblingEventTypes: Object;
declare var customDirectEventTypes: Object;
declare function createView(
reactTag: number,
viewName: string,
rootTag: number,
props: ?Object,
): void;
declare function manageChildren(
containerTag: number,
moveFromIndices: Array<number>,
moveToIndices: Array<number>,
addChildReactTags: Array<number>,
addAtIndices: Array<number>,
removeAtIndices: Array<number>,
): void;
declare function measure(hostComponent: mixed, callback: Function): void;
declare function measureInWindow(
nativeTag: ?number,
callback: Function,
): void;
declare function measureLayout(
nativeTag: mixed,
nativeNode: number,
onFail: Function,
onSuccess: Function,
): void;
declare function removeRootView(containerTag: number): void;
declare function removeSubviewsFromContainerWithID(containerId: number): void;
declare function replaceExistingNonRootView(): void;
declare function setChildren(
containerTag: number,
reactTags: Array<number>,
): void;
declare function updateView(
reactTag: number,
viewName: string,
props: ?Object,
): void;
declare function __takeSnapshot(
view?: 'window' | Element<any> | number,
options?: {
width?: number,
height?: number,
format?: 'png' | 'jpeg',
quality?: number,
},
): Promise<any>;
declare function setJSResponder(
reactTag: number,
blockNativeResponder: boolean,
): void;
declare function clearJSResponder(): void;
}
declare module 'FabricUIManager' {
declare function createNode(
reactTag: number,
viewName: string,
rootTag: number,
props: ?Object,
eventTarget: Object,
): Object;
declare function cloneNode(node: Object): Object;
declare function cloneNodeWithNewChildren(node: Object): Object;
declare function cloneNodeWithNewProps(
node: Object,
newProps: ?Object,
): Object;
declare function cloneNodeWithNewChildrenAndProps(
node: Object,
newProps: ?Object,
): Object;
declare function appendChild(node: Object, childNode: Object): void;
declare function createChildSet(rootTag: number): Object;
declare function appendChildToSet(childSet: Object, childNode: Object): void;
declare function completeRoot(rootTag: number, childSet: Object): void;
declare function registerEventHandler(
callback: (
eventTarget: null | Object,
type: RNTopLevelEventType,
payload: Object,
) => void,
): void;
declare function measure(
node: Node,
callback: MeasureOnSuccessCallback,
): void;
declare function measureInWindow(
node: Node,
callback: MeasureInWindowOnSuccessCallback,
): void;
declare function 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;
}
declare module 'BatchedBridge' {
declare function registerCallableModule(name: string, module: Object): void;
}
declare module 'ReactNativeViewConfigRegistry' {
declare var customBubblingEventTypes: Object;
declare var customDirectEventTypes: Object;
declare var eventTypes: Object;
declare function register(name: string, callback: ViewConfigGetter): string;
declare function get(name: string): ReactNativeBaseComponentViewConfig;
}