UNPKG

10 kBTypeScriptView Raw
1import type { ViewStyle, TextStyle, TransformsStyle, ImageStyle } from 'react-native';
2export type RequiredKeys<T, K extends keyof T> = T & Required<Pick<T, K>>;
3export interface StyleProps extends ViewStyle, TextStyle {
4 originX?: number;
5 originY?: number;
6 [key: string]: any;
7}
8/**
9 * A value that can be used both on the [JavaScript
10 * thread](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#javascript-thread)
11 * and the [UI
12 * thread](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#ui-thread).
13 *
14 * Shared values are defined using
15 * [useSharedValue](https://docs.swmansion.com/react-native-reanimated/docs/core/useSharedValue)
16 * hook. You access and modify shared values by their `.value` property.
17 */
18export interface SharedValue<Value = unknown> {
19 value: Value;
20 get(): Value;
21 set(value: Value | ((value: Value) => Value)): void;
22 addListener: (listenerID: number, listener: (value: Value) => void) => void;
23 removeListener: (listenerID: number) => void;
24 modify: (modifier?: <T extends Value>(value: T) => T, forceUpdate?: boolean) => void;
25}
26/**
27 * Due to pattern of `MaybeSharedValue` type present in `AnimatedProps`
28 * (`AnimatedStyle`), contravariance breaks types for animated styles etc.
29 * Instead of refactoring the code with small chances of success, we just
30 * disable contravariance for `SharedValue` in this problematic case.
31 */
32type SharedValueDisableContravariance<Value = unknown> = Omit<SharedValue<Value>, 'set'>;
33export interface Mutable<Value = unknown> extends SharedValue<Value> {
34 _isReanimatedSharedValue: true;
35 _animation?: AnimationObject<Value> | null;
36 /**
37 * `_value` prop should only be accessed by the `valueSetter` implementation
38 * which may make the decision about updating the mutable value depending on
39 * the provided new value. All other places should only attempt to modify the
40 * mutable by assigning to `value` prop directly or by calling the `set`
41 * method.
42 */
43 _value: Value;
44}
45export type ShareableRef<T = unknown> = {
46 __hostObjectShareableJSRef: T;
47};
48export type FlatShareableRef<T> = T extends ShareableRef<infer U> ? ShareableRef<U> : ShareableRef<T>;
49export type MapperRawInputs = unknown[];
50export type MapperOutputs = SharedValue[];
51export type MapperRegistry = {
52 start: (mapperID: number, worklet: () => void, inputs: MapperRawInputs, outputs?: MapperOutputs) => void;
53 stop: (mapperID: number) => void;
54};
55export type WorkletStackDetails = [
56 error: Error,
57 lineOffset: number,
58 columnOffset: number
59];
60type WorkletClosure = Record<string, unknown>;
61interface WorkletInitDataCommon {
62 code: string;
63}
64type WorkletInitDataRelease = WorkletInitDataCommon;
65interface WorkletInitDataDev extends WorkletInitDataCommon {
66 location: string;
67 sourceMap: string;
68 version: string;
69}
70interface WorkletBaseCommon {
71 __closure: WorkletClosure;
72 __workletHash: number;
73}
74interface WorkletBaseRelease extends WorkletBaseCommon {
75 __initData: WorkletInitDataRelease;
76}
77interface WorkletBaseDev extends WorkletBaseCommon {
78 __initData: WorkletInitDataDev;
79 /** `__stackDetails` is removed after parsing. */
80 __stackDetails?: WorkletStackDetails;
81}
82export type WorkletFunction<Args extends unknown[] = unknown[], ReturnValue = unknown> = ((...args: Args) => ReturnValue) & (WorkletBaseRelease | WorkletBaseDev);
83/**
84 * This function allows you to determine if a given function is a worklet. It
85 * only works with Reanimated Babel plugin enabled. Unless you are doing
86 * something with internals of Reanimated you shouldn't need to use this
87 * function.
88 *
89 * ### Note
90 *
91 * Do not call it before the worklet is declared, as it will always return false
92 * then. E.g.:
93 *
94 * ```ts
95 * isWorkletFunction(myWorklet); // Will always return false.
96 *
97 * function myWorklet() {
98 * 'worklet';
99 * }
100 * ```
101 *
102 * ### Maintainer note
103 *
104 * This function works well on the JS thread performance-wise, since the JIT can
105 * inline it. However, on other threads it will not get optimized and we will
106 * get a function call overhead. We want to change it in the future, but it's
107 * not feasible at the moment.
108 */
109export declare function isWorkletFunction<Args extends unknown[] = unknown[], ReturnValue = unknown, BuildType extends WorkletBaseDev | WorkletBaseRelease = WorkletBaseDev>(value: unknown): value is WorkletFunction<Args, ReturnValue> & BuildType;
110export type AnimatedPropsAdapterFunction = (props: Record<string, unknown>) => void;
111export type AnimatedPropsAdapterWorklet = WorkletFunction<[
112 props: Record<string, unknown>
113], void>;
114export interface NestedObject<T> {
115 [key: string]: NestedObjectValues<T>;
116}
117export type NestedObjectValues<T> = T | Array<NestedObjectValues<T>> | NestedObject<T>;
118type Animatable = number | string | Array<number>;
119export type AnimatableValueObject = {
120 [key: string]: Animatable;
121};
122export type AnimatableValue = Animatable | AnimatableValueObject;
123export interface AnimationObject<T = AnimatableValue> {
124 [key: string]: any;
125 callback?: AnimationCallback;
126 current?: T;
127 toValue?: AnimationObject<T>['current'];
128 startValue?: AnimationObject<T>['current'];
129 finished?: boolean;
130 strippedCurrent?: number;
131 cancelled?: boolean;
132 reduceMotion?: boolean;
133 __prefix?: string;
134 __suffix?: string;
135 onFrame: (animation: any, timestamp: Timestamp) => boolean;
136 onStart: (nextAnimation: any, current: any, timestamp: Timestamp, previousAnimation: any) => void;
137}
138export interface Animation<T extends AnimationObject> extends AnimationObject {
139 onFrame: (animation: T, timestamp: Timestamp) => boolean;
140 onStart: (nextAnimation: T, current: AnimatableValue, timestamp: Timestamp, previousAnimation: Animation<any> | null | T) => void;
141}
142export declare enum SensorType {
143 ACCELEROMETER = 1,
144 GYROSCOPE = 2,
145 GRAVITY = 3,
146 MAGNETIC_FIELD = 4,
147 ROTATION = 5
148}
149export declare enum IOSReferenceFrame {
150 XArbitraryZVertical = 0,
151 XArbitraryCorrectedZVertical = 1,
152 XMagneticNorthZVertical = 2,
153 XTrueNorthZVertical = 3,
154 Auto = 4
155}
156export type SensorConfig = {
157 interval: number | 'auto';
158 adjustToInterfaceOrientation: boolean;
159 iosReferenceFrame: IOSReferenceFrame;
160};
161export type AnimatedSensor<T extends Value3D | ValueRotation> = {
162 sensor: SharedValue<T>;
163 unregister: () => void;
164 isAvailable: boolean;
165 config: SensorConfig;
166};
167/**
168 * A function called upon animation completion. If the animation is cancelled,
169 * the callback will receive `false` as the argument; otherwise, it will receive
170 * `true`.
171 */
172export type AnimationCallback = (finished?: boolean, current?: AnimatableValue) => void;
173export type Timestamp = number;
174export type Value3D = {
175 x: number;
176 y: number;
177 z: number;
178 interfaceOrientation: InterfaceOrientation;
179};
180export type ValueRotation = {
181 qw: number;
182 qx: number;
183 qy: number;
184 qz: number;
185 yaw: number;
186 pitch: number;
187 roll: number;
188 interfaceOrientation: InterfaceOrientation;
189};
190export declare enum InterfaceOrientation {
191 ROTATION_0 = 0,
192 ROTATION_90 = 90,
193 ROTATION_180 = 180,
194 ROTATION_270 = 270
195}
196export type ShadowNodeWrapper = {
197 __hostObjectShadowNodeWrapper: never;
198};
199export declare enum KeyboardState {
200 UNKNOWN = 0,
201 OPENING = 1,
202 OPEN = 2,
203 CLOSING = 3,
204 CLOSED = 4
205}
206export type AnimatedKeyboardInfo = {
207 height: SharedValue<number>;
208 state: SharedValue<KeyboardState>;
209};
210/**
211 * @param x - A number representing X coordinate relative to the parent
212 * component.
213 * @param y - A number representing Y coordinate relative to the parent
214 * component.
215 * @param width - A number representing the width of the component.
216 * @param height - A number representing the height of the component.
217 * @param pageX - A number representing X coordinate relative to the screen.
218 * @param pageY - A number representing Y coordinate relative to the screen.
219 * @see https://docs.swmansion.com/react-native-reanimated/docs/advanced/measure#returns
220 */
221export interface MeasuredDimensions {
222 x: number;
223 y: number;
224 width: number;
225 height: number;
226 pageX: number;
227 pageY: number;
228}
229export interface AnimatedKeyboardOptions {
230 isStatusBarTranslucentAndroid?: boolean;
231 isNavigationBarTranslucentAndroid?: boolean;
232}
233/**
234 * @param System - If the `Reduce motion` accessibility setting is enabled on
235 * the device, disable the animation. Otherwise, enable the animation.
236 * @param Always - Disable the animation.
237 * @param Never - Enable the animation.
238 * @see https://docs.swmansion.com/react-native-reanimated/docs/guides/accessibility
239 */
240export declare enum ReduceMotion {
241 System = "system",
242 Always = "always",
243 Never = "never"
244}
245export type EasingFunction = (t: number) => number;
246export type TransformArrayItem = Extract<TransformsStyle['transform'], Array<unknown>>[number];
247type MaybeSharedValue<Value> = Value | (Value extends AnimatableValue ? SharedValueDisableContravariance<Value> : never);
248type MaybeSharedValueRecursive<Value> = Value extends (infer Item)[] ? SharedValueDisableContravariance<Item[]> | (MaybeSharedValueRecursive<Item> | Item)[] : Value extends object ? SharedValueDisableContravariance<Value> | {
249 [Key in keyof Value]: MaybeSharedValueRecursive<Value[Key]> | Value[Key];
250} : MaybeSharedValue<Value>;
251type DefaultStyle = ViewStyle & ImageStyle & TextStyle;
252export type AnimatedStyle<Style = DefaultStyle> = Style | MaybeSharedValueRecursive<Style>;
253export type AnimatedTransform = MaybeSharedValueRecursive<TransformsStyle['transform']>;
254/** @deprecated Please use {@link AnimatedStyle} type instead. */
255export type AnimateStyle<Style = DefaultStyle> = AnimatedStyle<Style>;
256/** @deprecated This type is no longer relevant. */
257export type StylesOrDefault<T> = 'style' extends keyof T ? MaybeSharedValueRecursive<T['style']> : Record<string, unknown>;
258export {};
259//# sourceMappingURL=commonTypes.d.ts.map
\No newline at end of file