mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35169 This reorganizes typing structure a bit. `Utilities.d.ts` was originally added for utilitiy types but I ended up leaving it a grab bag of types that didn't belong to any individual bit of code. Out of what is in it right now, `Insets` was actually public, and seems to have been imported. We also run into files around the renderer which are [currently overwritten](https://github.com/facebook/react-native/commits/e286da25fc83324363486eb668806aca179f74b3/Libraries/Renderer/implementations/ReactNativeRenderer.d.ts) by the React sync script. Finally, all of the top-level imports of `Utilities` were auto-generated by VS Code, but fail in real apps. I think this is because our tsconfig sets a `baseUrl` to allow resolution from the types folder, so the tooling in the RN repo will use that, but it breaks in real apps that don't have that mapping. This splits all these up into a couple separate directories that are hopefully easier to reason about, and removes `Omit` which has been a builtin type for quite some time (we were actually already using built-in `Omit`). Changelog: [General][Fixed] - Fixup TS Organization Reviewed By: cipolleschi Differential Revision: D40932319 fbshipit-source-id: 0b6e3e3eda603885b4dc01dcb9f5233aa546d128
158 lines
4.9 KiB
TypeScript
158 lines
4.9 KiB
TypeScript
/**
|
|
* 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.
|
|
*
|
|
* @format
|
|
*/
|
|
|
|
import type * as React from 'react';
|
|
import {
|
|
MeasureInWindowOnSuccessCallback,
|
|
MeasureLayoutOnSuccessCallback,
|
|
MeasureOnSuccessCallback,
|
|
} from '../../types/public/ReactNativeTypes';
|
|
|
|
export interface UIManagerStatic {
|
|
/**
|
|
* Capture an image of the screen, window or an individual view. The image
|
|
* will be stored in a temporary file that will only exist for as long as the
|
|
* app is running.
|
|
*
|
|
* The `view` argument can be the literal string `window` if you want to
|
|
* capture the entire window, or it can be a reference to a specific
|
|
* React Native component.
|
|
*
|
|
* The `options` argument may include:
|
|
* - width/height (number) - the width and height of the image to capture.
|
|
* - format (string) - either 'png' or 'jpeg'. Defaults to 'png'.
|
|
* - quality (number) - the quality when using jpeg. 0.0 - 1.0 (default).
|
|
*
|
|
* Returns a Promise<string> (tempFilePath)
|
|
* @platform ios
|
|
*/
|
|
takeSnapshot: (
|
|
view?: 'window' | React.ReactElement | number,
|
|
options?: {
|
|
width?: number | undefined;
|
|
height?: number | undefined;
|
|
format?: 'png' | 'jpeg' | undefined;
|
|
quality?: number | undefined;
|
|
},
|
|
) => Promise<string>;
|
|
|
|
/**
|
|
* Determines the location on screen, width, and height of the given view and
|
|
* returns the values via an async callback. If successful, the callback will
|
|
* be called with the following arguments:
|
|
*
|
|
* - x
|
|
* - y
|
|
* - width
|
|
* - height
|
|
* - pageX
|
|
* - pageY
|
|
*
|
|
* Note that these measurements are not available until after the rendering
|
|
* has been completed in native. If you need the measurements as soon as
|
|
* possible, consider using the [`onLayout`
|
|
* prop](docs/view.html#onlayout) instead.
|
|
*
|
|
* @deprecated Use `ref.measure` instead.
|
|
*/
|
|
measure(node: number, callback: MeasureOnSuccessCallback): void;
|
|
|
|
/**
|
|
* Determines the location of the given view in the window and returns the
|
|
* values via an async callback. If the React root view is embedded in
|
|
* another native view, this will give you the absolute coordinates. If
|
|
* successful, the callback will be called with the following
|
|
* arguments:
|
|
*
|
|
* - x
|
|
* - y
|
|
* - width
|
|
* - height
|
|
*
|
|
* Note that these measurements are not available until after the rendering
|
|
* has been completed in native.
|
|
*
|
|
* @deprecated Use `ref.measureInWindow` instead.
|
|
*/
|
|
measureInWindow(
|
|
node: number,
|
|
callback: MeasureInWindowOnSuccessCallback,
|
|
): void;
|
|
|
|
/**
|
|
* Like [`measure()`](#measure), but measures the view relative an ancestor,
|
|
* specified as `relativeToNativeNode`. This means that the returned x, y
|
|
* are relative to the origin x, y of the ancestor view.
|
|
*
|
|
* As always, to obtain a native node handle for a component, you can use
|
|
* `React.findNodeHandle(component)`.
|
|
*
|
|
* @deprecated Use `ref.measureLayout` instead.
|
|
*/
|
|
measureLayout(
|
|
node: number,
|
|
relativeToNativeNode: number,
|
|
onFail: () => void /* currently unused */,
|
|
onSuccess: MeasureLayoutOnSuccessCallback,
|
|
): void;
|
|
|
|
/**
|
|
* Automatically animates views to their new positions when the
|
|
* next layout happens.
|
|
*
|
|
* A common way to use this API is to call it before calling `setState`.
|
|
*
|
|
* Note that in order to get this to work on **Android** you need to set the following flags via `UIManager`:
|
|
*
|
|
* UIManager.setLayoutAnimationEnabledExperimental && UIManager.setLayoutAnimationEnabledExperimental(true);
|
|
*/
|
|
setLayoutAnimationEnabledExperimental(value: boolean): void;
|
|
|
|
/**
|
|
* Used to display an Android PopupMenu. If a menu item is pressed, the success callback will
|
|
* be called with the following arguments:
|
|
*
|
|
* - item - the menu item.
|
|
* - index - index of the pressed item in array. Returns `undefined` if cancelled.
|
|
*
|
|
* To obtain a native node handle for a component, you can use
|
|
* `React.findNodeHandle(component)`.
|
|
*
|
|
* Note that this works only on Android
|
|
*/
|
|
showPopupMenu(
|
|
node: number,
|
|
items: string[],
|
|
error: () => void /* currently unused */,
|
|
success: (item: string, index: number | undefined) => void,
|
|
): void;
|
|
|
|
getViewManagerConfig: (name: string) => {
|
|
Commands: {[key: string]: number};
|
|
};
|
|
|
|
hasViewManagerConfig: (name: string) => boolean;
|
|
|
|
/**
|
|
* Used to call a native view method from JavaScript
|
|
*
|
|
* reactTag - Id of react view.
|
|
* commandID - Id of the native method that should be called.
|
|
* commandArgs - Args of the native method that we can pass from JS to native.
|
|
*/
|
|
dispatchViewManagerCommand: (
|
|
reactTag: number | null,
|
|
commandID: number | string,
|
|
commandArgs?: Array<any>,
|
|
) => void;
|
|
}
|
|
|
|
export const UIManager: UIManagerStatic;
|
|
export type UIManager = UIManagerStatic;
|