-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
commonTypes.ts
205 lines (177 loc) · 4.56 KB
/
commonTypes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import {
PerpectiveTransform,
RotateTransform,
RotateXTransform,
RotateYTransform,
RotateZTransform,
ScaleTransform,
ScaleXTransform,
ScaleYTransform,
TranslateXTransform,
TranslateYTransform,
SkewXTransform,
SkewYTransform,
MatrixTransform,
ViewStyle,
TextStyle,
} from 'react-native';
export type TransformProperty =
| PerpectiveTransform
| RotateTransform
| RotateXTransform
| RotateYTransform
| RotateZTransform
| ScaleTransform
| ScaleXTransform
| ScaleYTransform
| TranslateXTransform
| TranslateYTransform
| SkewXTransform
| SkewYTransform
| MatrixTransform;
export interface StyleProps extends ViewStyle, TextStyle {
originX?: number;
originY?: number;
[key: string]: any;
}
export interface AnimatedStyle
extends Record<string, Animation<AnimationObject>> {
[key: string]: any;
transform?: Array<Record<string, Animation<AnimationObject>>>;
}
export interface SharedValue<T> {
value: T;
addListener: (listenerID: number, listener: (value: T) => void) => void;
removeListener: (listenerID: number) => void;
modify: (modifier: (value: T) => T) => void;
}
// The below type is used for HostObjects retured by the JSI API that don't have
// any accessable fields or methods but can carry data that is accessed from the
// c++ side. We add a field to the type to make it possible for typescript to recognize
// which JSI methods accept those types as arguments and to be able to correctly type
// check other methods that may use them. However, this field is not actually defined
// nor should be used for anything else as assigning any data to those objects will
// throw an error.
export type ShareableRef<T> = {
__hostObjectShareableJSRef: T;
};
export type ShareableSyncDataHolderRef<T> = {
__hostObjectShareableJSRefSyncDataHolder: T;
};
export type MapperRegistry = {
start: (
mapperID: number,
worklet: () => void,
inputs: SharedValue<any>[],
outputs?: SharedValue<any>[]
) => void;
stop: (mapperID: number) => void;
};
export type Context = Record<string, unknown>;
export interface WorkletFunction {
_closure?: Context;
__workletHash?: number;
__optimalization?: number;
}
export interface BasicWorkletFunction<T> extends WorkletFunction {
(): T;
}
export interface BasicWorkletFunctionOptional<T> extends WorkletFunction {
(): Partial<T>;
}
export interface NativeEvent<T> {
nativeEvent: T;
}
export interface ComplexWorkletFunction<A extends any[], R>
extends WorkletFunction {
(...args: A): R;
__remoteFunction?: (...args: A) => R;
}
export interface NestedObject<T> {
[key: string]: NestedObjectValues<T>;
}
export type NestedObjectValues<T> =
| T
| Array<NestedObjectValues<T>>
| NestedObject<T>;
export interface AdapterWorkletFunction extends WorkletFunction {
(value: NestedObject<string | number | AnimationObject>): void;
}
export type AnimatableValue = number | string | Array<number>;
export interface AnimationObject {
[key: string]: any;
callback: AnimationCallback;
current?: AnimatableValue;
toValue?: AnimationObject['current'];
startValue?: AnimationObject['current'];
finished?: boolean;
strippedCurrent?: number;
cancelled?: boolean;
__prefix?: string;
__suffix?: string;
onFrame: (animation: any, timestamp: Timestamp) => boolean;
onStart: (
nextAnimation: any,
current: any,
timestamp: Timestamp,
previousAnimation: any
) => void;
}
export interface Animation<T extends AnimationObject> extends AnimationObject {
onFrame: (animation: T, timestamp: Timestamp) => boolean;
onStart: (
nextAnimation: T,
current: T extends NumericAnimation ? number : AnimatableValue,
timestamp: Timestamp,
previousAnimation: T
) => void;
}
export enum SensorType {
ACCELEROMETER = 1,
GYROSCOPE = 2,
GRAVITY = 3,
MAGNETIC_FIELD = 4,
ROTATION = 5,
}
export interface NumericAnimation {
current?: number;
}
export type AnimationCallback = (
finished?: boolean,
current?: AnimatableValue
) => void;
export type Timestamp = number;
export type Value3D = {
x: number;
y: number;
z: number;
};
export type ValueRotation = {
qw: number;
qx: number;
qy: number;
qz: number;
yaw: number;
pitch: number;
roll: number;
};
export type ShadowNodeWrapper = object;
export enum KeyboardState {
UNKNOWN = 0,
OPENING = 1,
OPEN = 2,
CLOSING = 3,
CLOSED = 4,
}
export type AnimatedKeyboardInfo = {
height: SharedValue<number>;
state: SharedValue<KeyboardState>;
};
export interface MeasuredDimensions {
x: number;
y: number;
width: number;
height: number;
pageX: number;
pageY: number;
}