Add ReactNativeTypes for root options

This commit is contained in:
Rick Hanlon
2024-04-16 19:59:41 -04:00
parent 425a262527
commit 4b9bc21981
3 changed files with 31 additions and 39 deletions
+2 -19
View File
@@ -10,6 +10,7 @@
import type {ReactPortal, ReactNodeList} from 'shared/ReactTypes';
import type {ElementRef, Element, ElementType} from 'react';
import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
import type {RenderRootOptions} from './ReactNativeTypes';
import './ReactFabricInjection';
@@ -101,30 +102,12 @@ function nativeOnCaughtError(
defaultOnCaughtError(error, errorInfo);
}
type NativeRenderOptions = {
onUncaughtError?: (
error: mixed,
errorInfo: {+componentStack?: ?string},
) => void,
onCaughtError?: (
error: mixed,
errorInfo: {
+componentStack?: ?string,
+errorBoundary?: ?React$Component<any, any>,
},
) => void,
onRecoverableError?: (
error: mixed,
errorInfo: {+componentStack?: ?string},
) => void,
};
function render(
element: Element<ElementType>,
containerTag: number,
callback: ?() => void,
concurrentRoot: ?boolean,
options?: NativeRenderOptions,
options: ?RenderRootOptions,
): ?ElementRef<ElementType> {
if (disableLegacyMode && !concurrentRoot) {
throw new Error('render: Unsupported Legacy Mode API.');
+2 -19
View File
@@ -10,6 +10,7 @@
import type {ReactPortal, ReactNodeList} from 'shared/ReactTypes';
import type {ElementRef, Element, ElementType} from 'react';
import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
import type {RenderRootOptions} from './ReactNativeTypes';
import './ReactNativeInjection';
@@ -106,29 +107,11 @@ function nativeOnCaughtError(
defaultOnCaughtError(error, errorInfo);
}
type NativeRenderOptions = {
onUncaughtError?: (
error: mixed,
errorInfo: {+componentStack?: ?string},
) => void,
onCaughtError?: (
error: mixed,
errorInfo: {
+componentStack?: ?string,
+errorBoundary?: ?React$Component<any, any>,
},
) => void,
onRecoverableError?: (
error: mixed,
errorInfo: {+componentStack?: ?string},
) => void,
};
function render(
element: Element<ElementType>,
containerTag: number,
callback: ?() => void,
options?: NativeRenderOptions,
options: ?RenderRootOptions,
): ?ElementRef<ElementType> {
if (disableLegacyMode) {
throw new Error('render: Unsupported Legacy Mode API.');
+27 -1
View File
@@ -4,8 +4,13 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @noformat
* @flow strict
* @nolint
* @generated SignedSource<<f33ee88cc50bb00a16d281dce9952e21>>
* @generated SignedSource<<dda07b9b2e2bd7345cce0ff966d9fc46>>
*
* This file was sync'd from the facebook/react repository.
*/
import type {ElementRef, ElementType, Element, AbstractComponent} from 'react';
@@ -174,6 +179,25 @@ export type TouchedViewDataAtPoint = $ReadOnly<{
...InspectorData,
}>;
export type RenderRootOptions = {
onUncaughtError?: (
error: mixed,
errorInfo: {+componentStack?: ?string},
) => void,
onCaughtError?: (
error: mixed,
errorInfo: {
+componentStack?: ?string,
// $FlowFixMe[unclear-type] unknown props and state.
+errorBoundary?: ?React$Component<any, any>,
},
) => void,
onRecoverableError?: (
error: mixed,
errorInfo: {+componentStack?: ?string},
) => void,
};
/**
* Flat ReactNative renderer bundles are too big for Flow to parse efficiently.
* Provide minimal Flow typing for the high-level RN API and call it a day.
@@ -202,6 +226,7 @@ export type ReactNativeType = {
element: Element<ElementType>,
containerTag: number,
callback: ?() => void,
options: ?RenderRootOptions,
): ?ElementRef<ElementType>,
unmountComponentAtNode(containerTag: number): void,
unmountComponentAtNodeAndRemoveContainer(containerTag: number): void,
@@ -237,6 +262,7 @@ export type ReactFabricType = {
containerTag: number,
callback: ?() => void,
concurrentRoot: ?boolean,
options: ?RenderRootOptions,
): ?ElementRef<ElementType>,
unmountComponentAtNode(containerTag: number): void,
getNodeFromInternalInstanceHandle(