-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathRuntimeDecorator.h
More file actions
104 lines (92 loc) · 3.3 KB
/
RuntimeDecorator.h
File metadata and controls
104 lines (92 loc) · 3.3 KB
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
#pragma once
#include <jsi/jsi.h>
#include <stdio.h>
#include <memory>
#include <string>
#include <unordered_map>
#include "PlatformDepMethodsHolder.h"
using namespace facebook;
namespace reanimated {
using RequestFrameFunction =
std::function<void(jsi::Runtime &, const jsi::Value &)>;
using ScheduleOnJSFunction =
std::function<void(jsi::Runtime &, const jsi::Value &, const jsi::Value &)>;
using MakeShareableCloneFunction =
std::function<jsi::Value(jsi::Runtime &, const jsi::Value &)>;
using UpdateDataSynchronouslyFunction =
std::function<void(jsi::Runtime &, const jsi::Value &, const jsi::Value &)>;
enum RuntimeType {
/**
Represents any runtime that supports the concept of workletization
*/
Worklet,
/**
Represents the Reanimated UI worklet runtime specifically
*/
UI
};
typedef jsi::Runtime *RuntimePointer;
class RuntimeDecorator {
public:
static void decorateRuntime(jsi::Runtime &rt, const std::string &label);
static void decorateUIRuntime(
jsi::Runtime &rt,
const UpdatePropsFunction updateProps,
const MeasureFunction measure,
#ifdef RCT_NEW_ARCH_ENABLED
const RemoveShadowNodeFromRegistryFunction removeShadowNodeFromRegistry,
const DispatchCommandFunction dispatchCommand,
#else
const ScrollToFunction scrollTo,
#endif
const RequestFrameFunction requestFrame,
const ScheduleOnJSFunction scheduleOnJS,
const MakeShareableCloneFunction makeShareableClone,
const UpdateDataSynchronouslyFunction updateDataSynchronously,
const TimeProviderFunction getCurrentTime,
const RegisterSensorFunction registerSensor,
const UnregisterSensorFunction unregisterSensor,
const SetGestureStateFunction setGestureState,
const ProgressLayoutAnimationFunction progressLayoutAnimationFunction,
const EndLayoutAnimationFunction endLayoutAnimationFunction);
/**
Returns true if the given Runtime is the Reanimated UI-Thread Runtime.
*/
inline static bool isUIRuntime(jsi::Runtime &rt);
/**
Returns true if the given Runtime is a Runtime that supports the concept of
Workletization. (REA, Vision, ...)
*/
inline static bool isWorkletRuntime(jsi::Runtime &rt);
/**
Returns true if the given Runtime is the default React-JS Runtime.
*/
inline static bool isReactRuntime(jsi::Runtime &rt);
/**
Register the given Runtime. This function is required for every
RuntimeManager, otherwise future runtime checks will fail.
*/
static void registerRuntime(jsi::Runtime *runtime, RuntimeType runtimeType);
private:
static std::unordered_map<RuntimePointer, RuntimeType> &runtimeRegistry();
};
inline bool RuntimeDecorator::isUIRuntime(jsi::Runtime &rt) {
auto iterator = runtimeRegistry().find(&rt);
if (iterator == runtimeRegistry().end())
return false;
return iterator->second == RuntimeType::UI;
}
inline bool RuntimeDecorator::isWorkletRuntime(jsi::Runtime &rt) {
auto iterator = runtimeRegistry().find(&rt);
if (iterator == runtimeRegistry().end())
return false;
auto type = iterator->second;
return type == RuntimeType::UI || type == RuntimeType::Worklet;
}
inline bool RuntimeDecorator::isReactRuntime(jsi::Runtime &rt) {
auto iterator = runtimeRegistry().find(&rt);
if (iterator == runtimeRegistry().end())
return true;
return false;
}
} // namespace reanimated