-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
NativeReanimated.ts
147 lines (127 loc) · 4.22 KB
/
NativeReanimated.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
import { NativeModules } from 'react-native';
import {
ShareableRef,
ShareableSyncDataHolderRef,
Value3D,
ValueRotation,
} from '../commonTypes';
import { LayoutAnimationFunction } from '../layoutReanimation';
import { version as jsVersion } from '../../../package.json';
export class NativeReanimated {
native: boolean;
private InnerNativeModule: any;
constructor(native = true) {
if (global.__reanimatedModuleProxy === undefined && native) {
const { ReanimatedModule } = NativeModules;
ReanimatedModule?.installTurboModule();
}
this.InnerNativeModule = global.__reanimatedModuleProxy;
this.native = native;
if (native) {
this.checkVersion();
}
}
checkVersion(): void {
const cppVersion = global._REANIMATED_VERSION_CPP;
const ok = (() => {
if (
jsVersion.match(/^\d+\.\d+\.\d+$/) &&
cppVersion.match(/^\d+\.\d+\.\d+$/)
) {
// x.y.z, compare only major and minor, skip patch
const [jsMajor, jsMinor] = jsVersion.split('.');
const [cppMajor, cppMinor] = cppVersion.split('.');
return jsMajor === cppMajor && jsMinor === cppMinor;
} else {
// alpha, beta or rc, compare everything
return jsVersion === cppVersion;
}
})();
if (!ok) {
console.error(
`[Reanimated] Mismatch between JavaScript part and native part of Reanimated (${jsVersion} vs. ${cppVersion}). Did you forget to re-build the app after upgrading react-native-reanimated? If you use Expo Go, you must downgrade to ${cppVersion} which is bundled into Expo SDK.`
);
// TODO: detect Expo managed workflow
}
}
getTimestamp(): number {
throw new Error('stub implementation, used on the web only');
}
installCoreFunctions(
callGuard: <T extends Array<any>, U>(
fn: (...args: T) => U,
...args: T
) => void,
valueUnpacker: <T>(value: T) => T
): void {
return this.InnerNativeModule.installCoreFunctions(
callGuard,
valueUnpacker
);
}
makeShareableClone<T>(value: T): ShareableRef<T> {
return this.InnerNativeModule.makeShareableClone(value);
}
makeSynchronizedDataHolder<T>(
valueRef: ShareableRef<T>
): ShareableSyncDataHolderRef<T> {
return this.InnerNativeModule.makeSynchronizedDataHolder(valueRef);
}
getDataSynchronously<T>(ref: ShareableSyncDataHolderRef<T>): T {
return this.InnerNativeModule.getDataSynchronously(ref);
}
updateDataSynchronously<T>(
ref: ShareableSyncDataHolderRef<T>,
value: T
): void {
this.InnerNativeModule.updateDataSynchronously(ref, value);
}
scheduleOnUI<T>(shareable: ShareableRef<T>) {
return this.InnerNativeModule.scheduleOnUI(shareable);
}
registerSensor<T>(
sensorType: number,
interval: number,
handler: ShareableRef<T> | ((data: Value3D | ValueRotation) => void)
) {
return this.InnerNativeModule.registerSensor(sensorType, interval, handler);
}
unregisterSensor(sensorId: number) {
return this.InnerNativeModule.unregisterSensor(sensorId);
}
registerEventHandler<T>(
eventHash: string,
eventHandler: ShareableRef<T>
): string {
return this.InnerNativeModule.registerEventHandler(eventHash, eventHandler);
}
unregisterEventHandler(id: string): void {
return this.InnerNativeModule.unregisterEventHandler(id);
}
getViewProp<T>(
viewTag: string,
propName: string,
callback?: (result: T) => void
): Promise<T> {
return this.InnerNativeModule.getViewProp(viewTag, propName, callback);
}
configureLayoutAnimation(
viewTag: number,
type: string,
config: ShareableRef<Keyframe | LayoutAnimationFunction>
) {
this.InnerNativeModule.configureLayoutAnimation(viewTag, type, config);
}
enableLayoutAnimations(flag: boolean): void {
this.InnerNativeModule.enableLayoutAnimations(flag);
}
configureProps(uiProps: string[], nativeProps: string[]): void {
this.InnerNativeModule.configureProps(uiProps, nativeProps);
}
subscribeForKeyboardEvents(handler: ShareableRef<number>): number {
return this.InnerNativeModule.subscribeForKeyboardEvents(handler);
}
unsubscribeFromKeyboardEvents(listenerId: number): void {
this.InnerNativeModule.unsubscribeFromKeyboardEvents(listenerId);
}
}