1 | /**
|
2 | * Copyright (c) Meta Platforms, Inc. and affiliates.
|
3 | *
|
4 | * This source code is licensed under the MIT license found in the
|
5 | * LICENSE file in the root directory of this source tree.
|
6 | *
|
7 | * @format
|
8 | */
|
9 |
|
10 | import type * as React from 'react';
|
11 |
|
12 | export type MeasureOnSuccessCallback = (
|
13 | x: number,
|
14 | y: number,
|
15 | width: number,
|
16 | height: number,
|
17 | pageX: number,
|
18 | pageY: number,
|
19 | ) => void;
|
20 |
|
21 | export type MeasureInWindowOnSuccessCallback = (
|
22 | x: number,
|
23 | y: number,
|
24 | width: number,
|
25 | height: number,
|
26 | ) => void;
|
27 |
|
28 | export type MeasureLayoutOnSuccessCallback = (
|
29 | left: number,
|
30 | top: number,
|
31 | width: number,
|
32 | height: number,
|
33 | ) => void;
|
34 |
|
35 | /**
|
36 | * NativeMethods provides methods to access the underlying native component directly.
|
37 | * This can be useful in cases when you want to focus a view or measure its on-screen dimensions,
|
38 | * for example.
|
39 | * The methods described here are available on most of the default components provided by React Native.
|
40 | * Note, however, that they are not available on composite components that aren't directly backed by a
|
41 | * native view. This will generally include most components that you define in your own app.
|
42 | * For more information, see [Direct Manipulation](https://reactnative.dev/docs/direct-manipulation).
|
43 | * @see https://github.com/facebook/react-native/blob/master/Libraries/Renderer/shims/ReactNativeTypes.js#L87
|
44 | */
|
45 | export interface NativeMethods {
|
46 | /**
|
47 | * Determines the location on screen, width, and height of the given view and
|
48 | * returns the values via an async callback. If successful, the callback will
|
49 | * be called with the following arguments:
|
50 | *
|
51 | * - x
|
52 | * - y
|
53 | * - width
|
54 | * - height
|
55 | * - pageX
|
56 | * - pageY
|
57 | *
|
58 | * Note that these measurements are not available until after the rendering
|
59 | * has been completed in native. If you need the measurements as soon as
|
60 | * possible, consider using the [`onLayout`
|
61 | * prop](docs/view.html#onlayout) instead.
|
62 | */
|
63 | measure(callback: MeasureOnSuccessCallback): void;
|
64 |
|
65 | /**
|
66 | * Determines the location of the given view in the window and returns the
|
67 | * values via an async callback. If the React root view is embedded in
|
68 | * another native view, this will give you the absolute coordinates. If
|
69 | * successful, the callback will be called with the following
|
70 | * arguments:
|
71 | *
|
72 | * - x
|
73 | * - y
|
74 | * - width
|
75 | * - height
|
76 | *
|
77 | * Note that these measurements are not available until after the rendering
|
78 | * has been completed in native.
|
79 | */
|
80 | measureInWindow(callback: MeasureInWindowOnSuccessCallback): void;
|
81 |
|
82 | /**
|
83 | * Like [`measure()`](#measure), but measures the view relative an ancestor,
|
84 | * specified as `relativeToNativeComponentRef`. This means that the returned x, y
|
85 | * are relative to the origin x, y of the ancestor view.
|
86 | * _Can also be called with a relativeNativeNodeHandle but is deprecated._
|
87 | */
|
88 | measureLayout(
|
89 | relativeToNativeComponentRef:
|
90 | | React.ElementRef<HostComponent<unknown>>
|
91 | | number,
|
92 | onSuccess: MeasureLayoutOnSuccessCallback,
|
93 | onFail?: () => void,
|
94 | ): void;
|
95 |
|
96 | /**
|
97 | * This function sends props straight to native. They will not participate in
|
98 | * future diff process - this means that if you do not include them in the
|
99 | * next render, they will remain active (see [Direct
|
100 | * Manipulation](https://reactnative.dev/docs/direct-manipulation)).
|
101 | */
|
102 | setNativeProps(nativeProps: object): void;
|
103 |
|
104 | /**
|
105 | * Requests focus for the given input or view. The exact behavior triggered
|
106 | * will depend on the platform and type of view.
|
107 | */
|
108 | focus(): void;
|
109 |
|
110 | /**
|
111 | * Removes focus from an input or view. This is the opposite of `focus()`.
|
112 | */
|
113 | blur(): void;
|
114 |
|
115 | refs: {
|
116 | [key: string]: React.Component<any, any>;
|
117 | };
|
118 | }
|
119 |
|
120 | /**
|
121 | * @deprecated Use NativeMethods instead.
|
122 | */
|
123 | export type NativeMethodsMixin = NativeMethods;
|
124 | /**
|
125 | * @deprecated Use NativeMethods instead.
|
126 | */
|
127 | export type NativeMethodsMixinType = NativeMethods;
|
128 |
|
129 | /**
|
130 | * Represents a native component, such as those returned from `requireNativeComponent`.
|
131 | *
|
132 | * @see https://github.com/facebook/react-native/blob/v0.62.0-rc.5/Libraries/Renderer/shims/ReactNativeTypes.js
|
133 | *
|
134 | * @todo This should eventually be defined as an AbstractComponent, but that
|
135 | * should first be introduced in the React typings.
|
136 | */
|
137 | export interface HostComponent<P>
|
138 | extends Pick<
|
139 | React.ComponentClass<P>,
|
140 | Exclude<keyof React.ComponentClass<P>, 'new'>
|
141 | > {
|
142 | new (props: P, context?: any): React.Component<P> & Readonly<NativeMethods>;
|
143 | }
|