-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Expand file tree
/
Copy pathFabricUIManagerBinding.h
More file actions
162 lines (119 loc) · 5.29 KB
/
Copy pathFabricUIManagerBinding.h
File metadata and controls
162 lines (119 loc) · 5.29 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
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
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <memory>
#include <mutex>
#include <shared_mutex>
#include <unordered_map>
#include <fbjni/fbjni.h>
#include <react/jni/JRuntimeExecutor.h>
#include <react/jni/JRuntimeScheduler.h>
#include <react/jni/ReadableNativeMap.h>
#include <react/renderer/scheduler/SchedulerDelegate.h>
#include <react/renderer/scheduler/SurfaceHandler.h>
#include <react/renderer/uimanager/LayoutAnimationStatusDelegate.h>
#include <react/renderer/uimanager/primitives.h>
#include "JFabricUIManager.h"
#include "SurfaceHandlerBinding.h"
namespace facebook::react {
class ComponentFactory;
class EventBeatManager;
class FabricMountingManager;
class Instance;
class LayoutAnimationDriver;
class Scheduler;
class FabricUIManagerBinding : public jni::HybridClass<FabricUIManagerBinding>,
public SchedulerDelegate,
public LayoutAnimationStatusDelegate {
public:
constexpr static const char *const kJavaDescriptor = "Lcom/facebook/react/fabric/FabricUIManagerBinding;";
static void registerNatives();
// Must be kept public even though it is not used by any other class in React
// Native. Used by 3rd party libraries, for example Reanimated:
// https://github.com/software-mansion/react-native-reanimated/
std::shared_ptr<Scheduler> getScheduler();
private:
void setConstraints(
jint surfaceId,
jfloat minWidth,
jfloat maxWidth,
jfloat minHeight,
jfloat maxHeight,
jfloat offsetX,
jfloat offsetY,
jboolean isRTL,
jboolean doLeftAndRightSwapInRTL);
static void initHybrid(jni::alias_ref<jhybridobject> jobj);
void installFabricUIManager(
jni::alias_ref<JRuntimeExecutor::javaobject> runtimeExecutorHolder,
jni::alias_ref<JRuntimeScheduler::javaobject> runtimeSchedulerHolder,
jni::alias_ref<JFabricUIManager::javaobject> javaUIManager,
EventBeatManager *eventBeatManager,
ComponentFactory *componentsRegistry);
void startSurface(jint surfaceId, jni::alias_ref<jstring> moduleName, NativeMap *initialProps);
void startSurfaceWithConstraints(
jint surfaceId,
jni::alias_ref<jstring> moduleName,
NativeMap *initialProps,
jfloat minWidth,
jfloat maxWidth,
jfloat minHeight,
jfloat maxHeight,
jfloat offsetX,
jfloat offsetY,
jboolean isRTL,
jboolean doLeftAndRightSwapInRTL);
void stopSurface(jint surfaceId);
void startSurfaceWithSurfaceHandler(
jint surfaceId,
jni::alias_ref<SurfaceHandlerBinding::jhybridobject> surfaceHandlerBinding,
jboolean isMountable);
void stopSurfaceWithSurfaceHandler(jni::alias_ref<SurfaceHandlerBinding::jhybridobject> surfaceHandler);
void schedulerDidFinishTransaction(const std::shared_ptr<const MountingCoordinator> &mountingCoordinator) override;
void schedulerShouldRenderTransactions(
const std::shared_ptr<const MountingCoordinator> &mountingCoordinator) override;
void schedulerDidRequestPreliminaryViewAllocation(const ShadowNode &shadowNode) override;
void schedulerDidDispatchCommand(
const ShadowView &shadowView,
const std::string &commandName,
const folly::dynamic &args) override;
void schedulerDidSendAccessibilityEvent(const ShadowView &shadowView, const std::string &eventType) override;
void schedulerDidSetIsJSResponder(const ShadowView &shadowView, bool isJSResponder, bool blockNativeResponder)
override;
void schedulerShouldSynchronouslyUpdateViewOnUIThread(Tag tag, const folly::dynamic &props) override;
void schedulerDidUpdateShadowTree(const std::unordered_map<Tag, folly::dynamic> &tagToProps) override;
void schedulerShouldResumeAnimationFrameCallbacks() override;
void schedulerShouldPauseAnimationFrameCallbacks() override;
void setPixelDensity(float pointScaleFactor);
void driveCxxAnimations();
void drainPreallocateViewsQueue();
void reportMount(SurfaceId surfaceId);
jint findNextFocusableElement(jint parentTag, jint focusedTag, jint direction);
jintArray getRelativeAncestorList(jint rootTag, jint childTag);
void uninstallFabricUIManager();
// Private member variables
std::shared_mutex installMutex_;
std::shared_ptr<FabricMountingManager> mountingManager_;
std::shared_ptr<Scheduler> scheduler_;
std::shared_ptr<FabricMountingManager> getMountingManager(const char *locationHint);
// LayoutAnimations
void onAnimationStarted() override;
void onAllAnimationsComplete() override;
std::shared_ptr<LayoutAnimationDriver> animationDriver_;
// Roots not created through ReactSurface (non-bridgeless) will store their
// SurfaceHandler here, for other roots we keep a weak reference to the Java
// owner
std::unordered_map<SurfaceId, std::variant<SurfaceHandler, jni::weak_ref<SurfaceHandlerBinding::jhybridobject>>>
surfaceHandlerRegistry_{};
std::shared_mutex surfaceHandlerRegistryMutex_; // Protects `surfaceHandlerRegistry_`.
// Track pending transactions, one per surfaceId
std::mutex pendingTransactionsMutex_;
std::vector<MountingTransaction> pendingTransactions_;
float pointScaleFactor_ = 1;
bool enableFabricLogs_{false};
};
} // namespace facebook::react