1 | 'use strict';
|
2 | import type { ViewStyle, TextStyle } from 'react-native';
|
3 |
|
4 | export type RequiredKeys<T, K extends keyof T> = T & Required<Pick<T, K>>;
|
5 | export interface StyleProps extends ViewStyle, TextStyle {
|
6 | originX?: number;
|
7 | originY?: number;
|
8 | [key: string]: any;
|
9 | }
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | export interface SharedValue<Value = unknown> {
|
17 | value: Value;
|
18 | addListener: (listenerID: number, listener: (value: Value) => void) => void;
|
19 | removeListener: (listenerID: number) => void;
|
20 | modify: (
|
21 | modifier?: <T extends Value>(value: T) => T,
|
22 | forceUpdate?: boolean
|
23 | ) => void;
|
24 | }
|
25 |
|
26 | export interface Mutable<Value = unknown> extends SharedValue<Value> {
|
27 | _isReanimatedSharedValue: true;
|
28 | _animation?: AnimationObject<Value> | null;
|
29 | _value: Value;
|
30 | }
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | export type ShareableRef<T = unknown> = {
|
40 | __hostObjectShareableJSRef: T;
|
41 | };
|
42 |
|
43 |
|
44 |
|
45 | export type FlatShareableRef<T> = T extends ShareableRef<infer U>
|
46 | ? ShareableRef<U>
|
47 | : ShareableRef<T>;
|
48 |
|
49 | export type MapperRawInputs = unknown[];
|
50 |
|
51 | export type MapperOutputs = SharedValue[];
|
52 |
|
53 | export type MapperRegistry = {
|
54 | start: (
|
55 | mapperID: number,
|
56 | worklet: () => void,
|
57 | inputs: MapperRawInputs,
|
58 | outputs?: MapperOutputs
|
59 | ) => void;
|
60 | stop: (mapperID: number) => void;
|
61 | };
|
62 |
|
63 | export type WorkletStackDetails = [
|
64 | error: Error,
|
65 | lineOffset: number,
|
66 | columnOffset: number
|
67 | ];
|
68 |
|
69 | type WorkletClosure = Record<string, unknown>;
|
70 |
|
71 | interface WorkletInitDataCommon {
|
72 | code: string;
|
73 | }
|
74 |
|
75 | type WorkletInitDataRelease = WorkletInitDataCommon;
|
76 |
|
77 | interface WorkletInitDataDev extends WorkletInitDataCommon {
|
78 | location: string;
|
79 | sourceMap: string;
|
80 | version: string;
|
81 | }
|
82 |
|
83 | interface WorkletBaseCommon {
|
84 | __closure: WorkletClosure;
|
85 | __workletHash: number;
|
86 | }
|
87 |
|
88 | interface WorkletBaseRelease extends WorkletBaseCommon {
|
89 | __initData: WorkletInitDataRelease;
|
90 | }
|
91 |
|
92 | interface WorkletBaseDev extends WorkletBaseCommon {
|
93 | __initData: WorkletInitDataDev;
|
94 | |
95 |
|
96 |
|
97 | __stackDetails?: WorkletStackDetails;
|
98 | }
|
99 |
|
100 | export type WorkletFunction<
|
101 | Args extends unknown[] = unknown[],
|
102 | ReturnValue = unknown
|
103 | > = ((...args: Args) => ReturnValue) & (WorkletBaseRelease | WorkletBaseDev);
|
104 |
|
105 | /**
|
106 | * This function allows you to determine if a given function is a worklet. It only works
|
107 | * with Reanimated Babel plugin enabled. Unless you are doing something with internals of
|
108 | * Reanimated you shouldn't need to use this function.
|
109 | *
|
110 | * ### Note
|
111 | * Do not call it before the worklet is declared, as it will always return false then. E.g.:
|
112 | *
|
113 | * ```ts
|
114 | * isWorkletFunction(myWorklet); // Will always return false.
|
115 | *
|
116 | * function myWorklet() {
|
117 | * 'worklet';
|
118 | * };
|
119 | * ```
|
120 | *
|
121 | * ### Maintainer note
|
122 | * This function works well on the JS thread performance-wise, since the JIT can inline it.
|
123 | * However, on other threads it will not get optimized and we will get a function call overhead.
|
124 | * We want to change it in the future, but it's not feasible at the moment.
|
125 | */
|
126 | export function isWorkletFunction<
|
127 | Args extends unknown[] = unknown[],
|
128 | ReturnValue = unknown,
|
129 | BuildType extends WorkletBaseDev | WorkletBaseRelease = WorkletBaseDev
|
130 | >(value: unknown): value is WorkletFunction<Args, ReturnValue> & BuildType {
|
131 | 'worklet';
|
132 | // Since host objects always return true for `in` operator, we have to use dot notation to check if the property exists.
|
133 | // See https://github.com/facebook/hermes/blob/340726ef8cf666a7cce75bc60b02fa56b3e54560/lib/VM/JSObject.cpp#L1276.
|
134 | return (
|
135 | typeof value === 'function' &&
|
136 | !!(value as unknown as Record<string, unknown>).__workletHash
|
137 | );
|
138 | }
|
139 |
|
140 | export type AnimatedPropsAdapterFunction = (
|
141 | props: Record<string, unknown>
|
142 | ) => void;
|
143 |
|
144 | export type AnimatedPropsAdapterWorklet = WorkletFunction<
|
145 | [props: Record<string, unknown>],
|
146 | void
|
147 | >;
|
148 |
|
149 | export interface NestedObject<T> {
|
150 | [key: string]: NestedObjectValues<T>;
|
151 | }
|
152 |
|
153 | export type NestedObjectValues<T> =
|
154 | | T
|
155 | | Array<NestedObjectValues<T>>
|
156 | | NestedObject<T>;
|
157 |
|
158 | type Animatable = number | string | Array<number>;
|
159 |
|
160 | export type AnimatableValueObject = { [key: string]: Animatable };
|
161 |
|
162 | export type AnimatableValue = Animatable | AnimatableValueObject;
|
163 |
|
164 | export interface AnimationObject<T = AnimatableValue> {
|
165 | [key: string]: any;
|
166 | callback?: AnimationCallback;
|
167 | current?: T;
|
168 | toValue?: AnimationObject<T>['current'];
|
169 | startValue?: AnimationObject<T>['current'];
|
170 | finished?: boolean;
|
171 | strippedCurrent?: number;
|
172 | cancelled?: boolean;
|
173 | reduceMotion?: boolean;
|
174 |
|
175 | __prefix?: string;
|
176 | __suffix?: string;
|
177 | onFrame: (animation: any, timestamp: Timestamp) => boolean;
|
178 | onStart: (
|
179 | nextAnimation: any,
|
180 | current: any,
|
181 | timestamp: Timestamp,
|
182 | previousAnimation: any
|
183 | ) => void;
|
184 | }
|
185 |
|
186 | export interface Animation<T extends AnimationObject> extends AnimationObject {
|
187 | onFrame: (animation: T, timestamp: Timestamp) => boolean;
|
188 | onStart: (
|
189 | nextAnimation: T,
|
190 | current: AnimatableValue,
|
191 | timestamp: Timestamp,
|
192 | previousAnimation: Animation<any> | null | T
|
193 | ) => void;
|
194 | }
|
195 |
|
196 | export enum SensorType {
|
197 | ACCELEROMETER = 1,
|
198 | GYROSCOPE = 2,
|
199 | GRAVITY = 3,
|
200 | MAGNETIC_FIELD = 4,
|
201 | ROTATION = 5,
|
202 | }
|
203 | export enum IOSReferenceFrame {
|
204 | XArbitraryZVertical,
|
205 | XArbitraryCorrectedZVertical,
|
206 | XMagneticNorthZVertical,
|
207 | XTrueNorthZVertical,
|
208 | Auto,
|
209 | }
|
210 |
|
211 | export type SensorConfig = {
|
212 | interval: number | 'auto';
|
213 | adjustToInterfaceOrientation: boolean;
|
214 | iosReferenceFrame: IOSReferenceFrame;
|
215 | };
|
216 |
|
217 | export type AnimatedSensor<T extends Value3D | ValueRotation> = {
|
218 | sensor: SharedValue<T>;
|
219 | unregister: () => void;
|
220 | isAvailable: boolean;
|
221 | config: SensorConfig;
|
222 | };
|
223 |
|
224 |
|
225 |
|
226 |
|
227 | export type AnimationCallback = (
|
228 | finished?: boolean,
|
229 | current?: AnimatableValue
|
230 | ) => void;
|
231 |
|
232 | export type Timestamp = number;
|
233 |
|
234 | export type Value3D = {
|
235 | x: number;
|
236 | y: number;
|
237 | z: number;
|
238 | interfaceOrientation: InterfaceOrientation;
|
239 | };
|
240 |
|
241 | export type ValueRotation = {
|
242 | qw: number;
|
243 | qx: number;
|
244 | qy: number;
|
245 | qz: number;
|
246 | yaw: number;
|
247 | pitch: number;
|
248 | roll: number;
|
249 | interfaceOrientation: InterfaceOrientation;
|
250 | };
|
251 |
|
252 | export enum InterfaceOrientation {
|
253 | ROTATION_0 = 0,
|
254 | ROTATION_90 = 90,
|
255 | ROTATION_180 = 180,
|
256 | ROTATION_270 = 270,
|
257 | }
|
258 |
|
259 | export type ShadowNodeWrapper = {
|
260 | __hostObjectShadowNodeWrapper: never;
|
261 | };
|
262 |
|
263 | export enum KeyboardState {
|
264 | UNKNOWN = 0,
|
265 | OPENING = 1,
|
266 | OPEN = 2,
|
267 | CLOSING = 3,
|
268 | CLOSED = 4,
|
269 | }
|
270 |
|
271 | export type AnimatedKeyboardInfo = {
|
272 | height: SharedValue<number>;
|
273 | state: SharedValue<KeyboardState>;
|
274 | };
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 | export interface MeasuredDimensions {
|
286 | x: number;
|
287 | y: number;
|
288 | width: number;
|
289 | height: number;
|
290 | pageX: number;
|
291 | pageY: number;
|
292 | }
|
293 |
|
294 | export interface AnimatedKeyboardOptions {
|
295 | isStatusBarTranslucentAndroid?: boolean;
|
296 | }
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 | export enum ReduceMotion {
|
305 | System = 'system',
|
306 | Always = 'always',
|
307 | Never = 'never',
|
308 | }
|