mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
clang-format cpp
Summary: Ran `arc f` against some CPP files to be modified with the next diff to reduce the churn on it. ## Changelog [Android] [Changed] - Formatted cpp/h code with clang-format Reviewed By: javache Differential Revision: D19371785 fbshipit-source-id: b7f7b92c4cb9ec7f8da728bb577db29cf11fbb39
This commit is contained in:
committed by
Facebook Github Bot
parent
8d57691a60
commit
d5ba113bb2
@@ -16,9 +16,9 @@
|
||||
#include <jsi/JSIDynamic.h>
|
||||
#include <jsi/jsi.h>
|
||||
#include <react/components/scrollview/ScrollViewProps.h>
|
||||
#include <react/core/conversions.h>
|
||||
#include <react/core/EventBeat.h>
|
||||
#include <react/core/EventEmitter.h>
|
||||
#include <react/core/conversions.h>
|
||||
#include <react/debug/SystraceSection.h>
|
||||
#include <react/uimanager/ComponentDescriptorFactory.h>
|
||||
#include <react/uimanager/Scheduler.h>
|
||||
@@ -73,7 +73,6 @@ std::shared_ptr<Scheduler> Binding::getScheduler() {
|
||||
return scheduler_;
|
||||
}
|
||||
|
||||
|
||||
void Binding::startSurface(
|
||||
jint surfaceId,
|
||||
jni::alias_ref<jstring> moduleName,
|
||||
@@ -89,7 +88,11 @@ void Binding::startSurface(
|
||||
LayoutContext context;
|
||||
context.pointScaleFactor = pointScaleFactor_;
|
||||
scheduler->startSurface(
|
||||
surfaceId, moduleName->toStdString(), initialProps->consume(), {}, context);
|
||||
surfaceId,
|
||||
moduleName->toStdString(),
|
||||
initialProps->consume(),
|
||||
{},
|
||||
context);
|
||||
}
|
||||
|
||||
void Binding::startSurfaceWithConstraints(
|
||||
@@ -200,10 +203,12 @@ void Binding::installFabricUIManager(
|
||||
LOG(WARNING) << "Binding::installFabricUIManager() was called (address: "
|
||||
<< this << ").";
|
||||
|
||||
// Use std::lock and std::adopt_lock to prevent deadlocks by locking mutexes at the same time
|
||||
// Use std::lock and std::adopt_lock to prevent deadlocks by locking mutexes
|
||||
// at the same time
|
||||
std::lock(schedulerMutex_, javaUIManagerMutex_);
|
||||
std::lock_guard<std::mutex> schedulerLock(schedulerMutex_, std::adopt_lock);
|
||||
std::lock_guard<std::mutex> uiManagerLock(javaUIManagerMutex_, std::adopt_lock);
|
||||
std::lock_guard<std::mutex> uiManagerLock(
|
||||
javaUIManagerMutex_, std::adopt_lock);
|
||||
|
||||
javaUIManager_ = make_global(javaUIManager);
|
||||
|
||||
@@ -226,13 +231,15 @@ void Binding::installFabricUIManager(
|
||||
// TODO: T31905686 Create synchronous Event Beat
|
||||
jni::global_ref<jobject> localJavaUIManager = javaUIManager_;
|
||||
EventBeat::Factory synchronousBeatFactory =
|
||||
[eventBeatManager, runtimeExecutor, localJavaUIManager](EventBeat::SharedOwnerBox const &ownerBox) {
|
||||
[eventBeatManager, runtimeExecutor, localJavaUIManager](
|
||||
EventBeat::SharedOwnerBox const &ownerBox) {
|
||||
return std::make_unique<AsyncEventBeat>(
|
||||
ownerBox, eventBeatManager, runtimeExecutor, localJavaUIManager);
|
||||
};
|
||||
|
||||
EventBeat::Factory asynchronousBeatFactory =
|
||||
[eventBeatManager, runtimeExecutor, localJavaUIManager](EventBeat::SharedOwnerBox const &ownerBox) {
|
||||
[eventBeatManager, runtimeExecutor, localJavaUIManager](
|
||||
EventBeat::SharedOwnerBox const &ownerBox) {
|
||||
return std::make_unique<AsyncEventBeat>(
|
||||
ownerBox, eventBeatManager, runtimeExecutor, localJavaUIManager);
|
||||
};
|
||||
@@ -244,12 +251,14 @@ void Binding::installFabricUIManager(
|
||||
|
||||
// Keep reference to config object and cache some feature flags here
|
||||
reactNativeConfig_ = config;
|
||||
shouldCollateRemovesAndDeletes_ = reactNativeConfig_->getBool("react_fabric:enable_removedelete_collation_android");
|
||||
shouldCollateRemovesAndDeletes_ = reactNativeConfig_->getBool(
|
||||
"react_fabric:enable_removedelete_collation_android");
|
||||
collapseDeleteCreateMountingInstructions_ = reactNativeConfig_->getBool(
|
||||
"react_fabric:enabled_collapse_delete_create_mounting_instructions");
|
||||
;
|
||||
|
||||
disablePreallocateViews_ = reactNativeConfig_->getBool("react_fabric:disabled_view_preallocation_android");
|
||||
disablePreallocateViews_ = reactNativeConfig_->getBool(
|
||||
"react_fabric:disabled_view_preallocation_android");
|
||||
|
||||
auto toolbox = SchedulerToolbox{};
|
||||
toolbox.contextContainer = contextContainer;
|
||||
@@ -263,10 +272,12 @@ void Binding::installFabricUIManager(
|
||||
void Binding::uninstallFabricUIManager() {
|
||||
LOG(WARNING) << "Binding::uninstallFabricUIManager() was called (address: "
|
||||
<< this << ").";
|
||||
// Use std::lock and std::adopt_lock to prevent deadlocks by locking mutexes at the same time
|
||||
// Use std::lock and std::adopt_lock to prevent deadlocks by locking mutexes
|
||||
// at the same time
|
||||
std::lock(schedulerMutex_, javaUIManagerMutex_);
|
||||
std::lock_guard<std::mutex> schedulerLock(schedulerMutex_, std::adopt_lock);
|
||||
std::lock_guard<std::mutex> uiManagerLock(javaUIManagerMutex_, std::adopt_lock);
|
||||
std::lock_guard<std::mutex> uiManagerLock(
|
||||
javaUIManagerMutex_, std::adopt_lock);
|
||||
|
||||
scheduler_ = nullptr;
|
||||
javaUIManager_ = nullptr;
|
||||
@@ -279,8 +290,9 @@ inline local_ref<ReadableMap::javaobject> castReadableMap(
|
||||
}
|
||||
|
||||
inline local_ref<ReadableArray::javaobject> castReadableArray(
|
||||
local_ref<ReadableNativeArray::javaobject> nativeArray) {
|
||||
return make_local(reinterpret_cast<ReadableArray::javaobject>(nativeArray.get()));
|
||||
local_ref<ReadableNativeArray::javaobject> nativeArray) {
|
||||
return make_local(
|
||||
reinterpret_cast<ReadableArray::javaobject>(nativeArray.get()));
|
||||
}
|
||||
|
||||
// TODO: this method will be removed when binding for components are code-gen
|
||||
@@ -351,8 +363,8 @@ local_ref<JMountItem::javaobject> createUpdateLayoutMountItem(
|
||||
oldChildShadowView.layoutMetrics != newChildShadowView.layoutMetrics) {
|
||||
static auto updateLayoutInstruction =
|
||||
jni::findClassStatic(UIManagerJavaDescriptor)
|
||||
->getMethod<alias_ref<JMountItem>(jint, jint, jint, jint, jint, jint)>(
|
||||
"updateLayoutMountItem");
|
||||
->getMethod<alias_ref<JMountItem>(
|
||||
jint, jint, jint, jint, jint, jint)>("updateLayoutMountItem");
|
||||
auto layoutMetrics = newChildShadowView.layoutMetrics;
|
||||
auto pointScaleFactor = layoutMetrics.pointScaleFactor;
|
||||
auto frame = layoutMetrics.frame;
|
||||
@@ -361,7 +373,8 @@ local_ref<JMountItem::javaobject> createUpdateLayoutMountItem(
|
||||
int y = round(frame.origin.y * pointScaleFactor);
|
||||
int w = round(frame.size.width * pointScaleFactor);
|
||||
int h = round(frame.size.height * pointScaleFactor);
|
||||
auto layoutDirection = toInt(newChildShadowView.layoutMetrics.layoutDirection);
|
||||
auto layoutDirection =
|
||||
toInt(newChildShadowView.layoutMetrics.layoutDirection);
|
||||
return updateLayoutInstruction(
|
||||
javaUIManager, newChildShadowView.tag, x, y, w, h, layoutDirection);
|
||||
}
|
||||
@@ -370,20 +383,20 @@ local_ref<JMountItem::javaobject> createUpdateLayoutMountItem(
|
||||
}
|
||||
|
||||
local_ref<JMountItem::javaobject> createUpdatePaddingMountItem(
|
||||
const jni::global_ref<jobject> &javaUIManager,
|
||||
const ShadowViewMutation &mutation) {
|
||||
|
||||
const jni::global_ref<jobject> &javaUIManager,
|
||||
const ShadowViewMutation &mutation) {
|
||||
auto oldChildShadowView = mutation.oldChildShadowView;
|
||||
auto newChildShadowView = mutation.newChildShadowView;
|
||||
|
||||
if (oldChildShadowView.layoutMetrics.contentInsets == newChildShadowView.layoutMetrics.contentInsets) {
|
||||
if (oldChildShadowView.layoutMetrics.contentInsets ==
|
||||
newChildShadowView.layoutMetrics.contentInsets) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static auto updateLayoutInstruction =
|
||||
jni::findClassStatic(UIManagerJavaDescriptor)
|
||||
->getMethod<alias_ref<JMountItem>(jint, jint, jint, jint, jint)>(
|
||||
"updatePaddingMountItem");
|
||||
jni::findClassStatic(UIManagerJavaDescriptor)
|
||||
->getMethod<alias_ref<JMountItem>(jint, jint, jint, jint, jint)>(
|
||||
"updatePaddingMountItem");
|
||||
|
||||
auto layoutMetrics = newChildShadowView.layoutMetrics;
|
||||
auto pointScaleFactor = layoutMetrics.pointScaleFactor;
|
||||
@@ -394,7 +407,8 @@ local_ref<JMountItem::javaobject> createUpdatePaddingMountItem(
|
||||
int right = round(contentInsets.right * pointScaleFactor);
|
||||
int bottom = round(contentInsets.bottom * pointScaleFactor);
|
||||
|
||||
return updateLayoutInstruction(javaUIManager, newChildShadowView.tag, left, top, right, bottom);
|
||||
return updateLayoutInstruction(
|
||||
javaUIManager, newChildShadowView.tag, left, top, right, bottom);
|
||||
}
|
||||
|
||||
local_ref<JMountItem::javaobject> createInsertMountItem(
|
||||
@@ -439,9 +453,9 @@ local_ref<JMountItem::javaobject> createUpdateStateMountItem(
|
||||
const jni::global_ref<jobject> &javaUIManager,
|
||||
const ShadowViewMutation &mutation) {
|
||||
static auto updateStateInstruction =
|
||||
jni::findClassStatic(UIManagerJavaDescriptor)
|
||||
->getMethod<alias_ref<JMountItem>(jint, jobject)>(
|
||||
"updateStateMountItem");
|
||||
jni::findClassStatic(UIManagerJavaDescriptor)
|
||||
->getMethod<alias_ref<JMountItem>(jint, jobject)>(
|
||||
"updateStateMountItem");
|
||||
|
||||
auto state = mutation.newChildShadowView.state;
|
||||
|
||||
@@ -456,9 +470,9 @@ local_ref<JMountItem::javaobject> createUpdateStateMountItem(
|
||||
}
|
||||
|
||||
return updateStateInstruction(
|
||||
javaUIManager,
|
||||
mutation.newChildShadowView.tag,
|
||||
(javaStateWrapper != nullptr ? javaStateWrapper.get() : nullptr));
|
||||
javaUIManager,
|
||||
mutation.newChildShadowView.tag,
|
||||
(javaStateWrapper != nullptr ? javaStateWrapper.get() : nullptr));
|
||||
}
|
||||
|
||||
local_ref<JMountItem::javaobject> createRemoveMountItem(
|
||||
@@ -487,14 +501,13 @@ local_ref<JMountItem::javaobject> createDeleteMountItem(
|
||||
}
|
||||
|
||||
local_ref<JMountItem::javaobject> createRemoveAndDeleteMultiMountItem(
|
||||
const jni::global_ref<jobject> &javaUIManager,
|
||||
const std::vector<RemoveDeleteMetadata> &metadata) {
|
||||
|
||||
const jni::global_ref<jobject> &javaUIManager,
|
||||
const std::vector<RemoveDeleteMetadata> &metadata) {
|
||||
auto env = Environment::current();
|
||||
auto removeAndDeleteArray = env->NewIntArray(metadata.size()*4);
|
||||
auto removeAndDeleteArray = env->NewIntArray(metadata.size() * 4);
|
||||
int position = 0;
|
||||
jint temp[4];
|
||||
for (const auto& x : metadata) {
|
||||
for (const auto &x : metadata) {
|
||||
temp[0] = x.tag;
|
||||
temp[1] = x.parentTag;
|
||||
temp[2] = x.index;
|
||||
@@ -504,30 +517,34 @@ local_ref<JMountItem::javaobject> createRemoveAndDeleteMultiMountItem(
|
||||
}
|
||||
|
||||
static auto removeDeleteMultiInstruction =
|
||||
jni::findClassStatic(UIManagerJavaDescriptor)
|
||||
->getMethod<alias_ref<JMountItem>(jintArray)>("removeDeleteMultiMountItem");
|
||||
jni::findClassStatic(UIManagerJavaDescriptor)
|
||||
->getMethod<alias_ref<JMountItem>(jintArray)>(
|
||||
"removeDeleteMultiMountItem");
|
||||
|
||||
auto ret = removeDeleteMultiInstruction(javaUIManager, removeAndDeleteArray);
|
||||
|
||||
// It is not strictly necessary to manually delete the ref here, in this particular case.
|
||||
// If JNI memory is being allocated in a loop, it's easy to overload the localref table
|
||||
// and crash; this is not possible in this case since the JNI would automatically clear this
|
||||
// ref when it goes out of scope, anyway. However, this is being left here as a reminder of
|
||||
// good hygiene and to be careful with JNI-allocated memory in general.
|
||||
// It is not strictly necessary to manually delete the ref here, in this
|
||||
// particular case. If JNI memory is being allocated in a loop, it's easy to
|
||||
// overload the localref table and crash; this is not possible in this case
|
||||
// since the JNI would automatically clear this ref when it goes out of scope,
|
||||
// anyway. However, this is being left here as a reminder of good hygiene and
|
||||
// to be careful with JNI-allocated memory in general.
|
||||
env->DeleteLocalRef(removeAndDeleteArray);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// TODO T48019320: because we pass initial props and state to the Create (and preallocate) mount instruction,
|
||||
// we technically don't need to pass the first Update to any components. Dedupe?
|
||||
// TODO T48019320: because we pass initial props and state to the Create (and
|
||||
// preallocate) mount instruction, we technically don't need to pass the first
|
||||
// Update to any components. Dedupe?
|
||||
local_ref<JMountItem::javaobject> createCreateMountItem(
|
||||
const jni::global_ref<jobject> &javaUIManager,
|
||||
const ShadowViewMutation &mutation,
|
||||
const Tag surfaceId) {
|
||||
static auto createJavaInstruction =
|
||||
jni::findClassStatic(UIManagerJavaDescriptor)
|
||||
->getMethod<alias_ref<JMountItem>(jstring, ReadableMap::javaobject, jobject, jint, jint, jboolean)>(
|
||||
->getMethod<alias_ref<JMountItem>(
|
||||
jstring, ReadableMap::javaobject, jobject, jint, jint, jboolean)>(
|
||||
"createMountItem");
|
||||
|
||||
auto newChildShadowView = mutation.newChildShadowView;
|
||||
@@ -539,7 +556,7 @@ local_ref<JMountItem::javaobject> createCreateMountItem(
|
||||
newChildShadowView.layoutMetrics != EmptyLayoutMetrics;
|
||||
|
||||
local_ref<ReadableMap::javaobject> props = castReadableMap(
|
||||
ReadableNativeMap::newObjectCxxArgs(newChildShadowView.props->rawProps));
|
||||
ReadableNativeMap::newObjectCxxArgs(newChildShadowView.props->rawProps));
|
||||
|
||||
// Do not hold onto Java object from C
|
||||
// We DO want to hold onto C object from Java, since we don't know the
|
||||
@@ -570,7 +587,8 @@ void Binding::schedulerDidFinishTransaction(
|
||||
|
||||
jni::global_ref<jobject> localJavaUIManager = getJavaUIManager();
|
||||
if (!localJavaUIManager) {
|
||||
LOG(ERROR) << "Binding::schedulerDidFinishTransaction: JavaUIManager disappeared";
|
||||
LOG(ERROR)
|
||||
<< "Binding::schedulerDidFinishTransaction: JavaUIManager disappeared";
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -651,16 +669,20 @@ void Binding::schedulerDidFinishTransaction(
|
||||
oldChildShadowView.layoutMetrics == EmptyLayoutMetrics;
|
||||
|
||||
// Handle accumulated removals/deletions
|
||||
if (shouldCollateRemovesAndDeletes_ && mutation.type != ShadowViewMutation::Remove && mutation.type != ShadowViewMutation::Delete) {
|
||||
if (shouldCollateRemovesAndDeletes_ &&
|
||||
mutation.type != ShadowViewMutation::Remove &&
|
||||
mutation.type != ShadowViewMutation::Delete) {
|
||||
if (toRemove.size() > 0) {
|
||||
mountItems[position++] = createRemoveAndDeleteMultiMountItem(localJavaUIManager, toRemove);
|
||||
mountItems[position++] =
|
||||
createRemoveAndDeleteMultiMountItem(localJavaUIManager, toRemove);
|
||||
toRemove.clear();
|
||||
}
|
||||
}
|
||||
|
||||
switch (mutation.type) {
|
||||
case ShadowViewMutation::Create: {
|
||||
if (disablePreallocateViews_ || mutation.newChildShadowView.props->revision > 1 ||
|
||||
if (disablePreallocateViews_ ||
|
||||
mutation.newChildShadowView.props->revision > 1 ||
|
||||
deletedViewTags.find(mutation.newChildShadowView.tag) !=
|
||||
deletedViewTags.end()) {
|
||||
mountItems[position++] =
|
||||
@@ -671,9 +693,15 @@ void Binding::schedulerDidFinishTransaction(
|
||||
case ShadowViewMutation::Remove: {
|
||||
if (!isVirtual) {
|
||||
if (shouldCollateRemovesAndDeletes_) {
|
||||
toRemove.push_back(RemoveDeleteMetadata{mutation.oldChildShadowView.tag, mutation.parentShadowView.tag, mutation.index, true, false});
|
||||
toRemove.push_back(
|
||||
RemoveDeleteMetadata{mutation.oldChildShadowView.tag,
|
||||
mutation.parentShadowView.tag,
|
||||
mutation.index,
|
||||
true,
|
||||
false});
|
||||
} else {
|
||||
mountItems[position++] = createRemoveMountItem(localJavaUIManager, mutation);
|
||||
mountItems[position++] =
|
||||
createRemoveMountItem(localJavaUIManager, mutation);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -681,15 +709,22 @@ void Binding::schedulerDidFinishTransaction(
|
||||
case ShadowViewMutation::Delete: {
|
||||
if (shouldCollateRemovesAndDeletes_) {
|
||||
// It is impossible to delete without removing node first
|
||||
const auto& it = std::find_if(std::begin(toRemove), std::end(toRemove), [&mutation](const auto& x) { return x.tag == mutation.oldChildShadowView.tag; });
|
||||
const auto &it = std::find_if(
|
||||
std::begin(toRemove),
|
||||
std::end(toRemove),
|
||||
[&mutation](const auto &x) {
|
||||
return x.tag == mutation.oldChildShadowView.tag;
|
||||
});
|
||||
|
||||
if (it != std::end(toRemove)) {
|
||||
it->shouldDelete = true;
|
||||
} else {
|
||||
toRemove.push_back(RemoveDeleteMetadata{mutation.oldChildShadowView.tag, -1, -1, false, true});
|
||||
toRemove.push_back(RemoveDeleteMetadata{
|
||||
mutation.oldChildShadowView.tag, -1, -1, false, true});
|
||||
}
|
||||
} else {
|
||||
mountItems[position++] = createDeleteMountItem(localJavaUIManager, mutation);
|
||||
mountItems[position++] =
|
||||
createDeleteMountItem(localJavaUIManager, mutation);
|
||||
}
|
||||
|
||||
deletedViewTags.insert(mutation.oldChildShadowView.tag);
|
||||
@@ -719,7 +754,8 @@ void Binding::schedulerDidFinishTransaction(
|
||||
mountItems[position++] = updateLayoutMountItem;
|
||||
}
|
||||
|
||||
auto updatePaddingMountItem = createUpdatePaddingMountItem(localJavaUIManager, mutation);
|
||||
auto updatePaddingMountItem =
|
||||
createUpdatePaddingMountItem(localJavaUIManager, mutation);
|
||||
if (updatePaddingMountItem) {
|
||||
mountItems[position++] = updatePaddingMountItem;
|
||||
}
|
||||
@@ -741,7 +777,8 @@ void Binding::schedulerDidFinishTransaction(
|
||||
mountItems[position++] =
|
||||
createInsertMountItem(localJavaUIManager, mutation);
|
||||
|
||||
if (disablePreallocateViews_ || mutation.newChildShadowView.props->revision > 1 ||
|
||||
if (disablePreallocateViews_ ||
|
||||
mutation.newChildShadowView.props->revision > 1 ||
|
||||
deletedViewTags.find(mutation.newChildShadowView.tag) !=
|
||||
deletedViewTags.end()) {
|
||||
mountItems[position++] =
|
||||
@@ -769,7 +806,7 @@ void Binding::schedulerDidFinishTransaction(
|
||||
|
||||
// Padding
|
||||
auto updatePaddingMountItem =
|
||||
createUpdatePaddingMountItem(localJavaUIManager, mutation);
|
||||
createUpdatePaddingMountItem(localJavaUIManager, mutation);
|
||||
if (updatePaddingMountItem) {
|
||||
mountItems[position++] = updatePaddingMountItem;
|
||||
}
|
||||
@@ -792,12 +829,14 @@ void Binding::schedulerDidFinishTransaction(
|
||||
|
||||
// Handle remaining removals and deletions
|
||||
if (shouldCollateRemovesAndDeletes_ && toRemove.size() > 0) {
|
||||
mountItems[position++] = createRemoveAndDeleteMultiMountItem(localJavaUIManager, toRemove);
|
||||
mountItems[position++] =
|
||||
createRemoveAndDeleteMultiMountItem(localJavaUIManager, toRemove);
|
||||
toRemove.clear();
|
||||
}
|
||||
|
||||
if (position <= 0) {
|
||||
// If there are no mountItems to be sent to the platform, then it is not necessary to even call.
|
||||
// If there are no mountItems to be sent to the platform, then it is not
|
||||
// necessary to even call.
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -810,10 +849,17 @@ void Binding::schedulerDidFinishTransaction(
|
||||
auto batch = createMountItemsBatchContainer(
|
||||
localJavaUIManager, mountItemsArray.get(), position, commitNumber);
|
||||
|
||||
static auto scheduleMountItem =
|
||||
jni::findClassStatic(UIManagerJavaDescriptor)
|
||||
->getMethod<void(JMountItem::javaobject, jint, jlong, jlong, jlong, jlong, jlong, jlong, jlong)>(
|
||||
"scheduleMountItem");
|
||||
static auto scheduleMountItem = jni::findClassStatic(UIManagerJavaDescriptor)
|
||||
->getMethod<void(
|
||||
JMountItem::javaobject,
|
||||
jint,
|
||||
jlong,
|
||||
jlong,
|
||||
jlong,
|
||||
jlong,
|
||||
jlong,
|
||||
jlong,
|
||||
jlong)>("scheduleMountItem");
|
||||
|
||||
long finishTransactionEndTime = monotonicTimeInMilliseconds();
|
||||
|
||||
@@ -837,14 +883,14 @@ void Binding::setPixelDensity(float pointScaleFactor) {
|
||||
void Binding::schedulerDidRequestPreliminaryViewAllocation(
|
||||
const SurfaceId surfaceId,
|
||||
const ShadowView &shadowView) {
|
||||
|
||||
if (disablePreallocateViews_) {
|
||||
return;
|
||||
}
|
||||
|
||||
jni::global_ref<jobject> localJavaUIManager = getJavaUIManager();
|
||||
if (!localJavaUIManager) {
|
||||
LOG(ERROR) << "Binding::schedulerDidRequestPreliminaryViewAllocation: JavaUIManager disappeared";
|
||||
LOG(ERROR)
|
||||
<< "Binding::schedulerDidRequestPreliminaryViewAllocation: JavaUIManager disappeared";
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -881,28 +927,28 @@ void Binding::schedulerDidRequestPreliminaryViewAllocation(
|
||||
}
|
||||
|
||||
void Binding::schedulerDidDispatchCommand(
|
||||
const ShadowView &shadowView,
|
||||
std::string const &commandName,
|
||||
folly::dynamic const args) {
|
||||
|
||||
const ShadowView &shadowView,
|
||||
std::string const &commandName,
|
||||
folly::dynamic const args) {
|
||||
jni::global_ref<jobject> localJavaUIManager = getJavaUIManager();
|
||||
if (!localJavaUIManager) {
|
||||
LOG(ERROR) << "Binding::schedulerDidDispatchCommand: JavaUIManager disappeared";
|
||||
LOG(ERROR)
|
||||
<< "Binding::schedulerDidDispatchCommand: JavaUIManager disappeared";
|
||||
return;
|
||||
}
|
||||
|
||||
static auto dispatchCommand =
|
||||
jni::findClassStatic(UIManagerJavaDescriptor)
|
||||
->getMethod<void(
|
||||
jint, jstring, ReadableArray::javaobject)>(
|
||||
"dispatchCommand");
|
||||
jni::findClassStatic(UIManagerJavaDescriptor)
|
||||
->getMethod<void(jint, jstring, ReadableArray::javaobject)>(
|
||||
"dispatchCommand");
|
||||
|
||||
local_ref<JString> command = make_jstring(commandName);
|
||||
|
||||
local_ref<ReadableArray::javaobject> argsArray = castReadableArray(
|
||||
ReadableNativeArray::newObjectCxxArgs(args));
|
||||
local_ref<ReadableArray::javaobject> argsArray =
|
||||
castReadableArray(ReadableNativeArray::newObjectCxxArgs(args));
|
||||
|
||||
dispatchCommand(localJavaUIManager, shadowView.tag, command.get(), argsArray.get());
|
||||
dispatchCommand(
|
||||
localJavaUIManager, shadowView.tag, command.get(), argsArray.get());
|
||||
}
|
||||
|
||||
void Binding::schedulerDidSetJSResponder(
|
||||
@@ -910,7 +956,6 @@ void Binding::schedulerDidSetJSResponder(
|
||||
const ShadowView &shadowView,
|
||||
const ShadowView &initialShadowView,
|
||||
bool blockNativeResponder) {
|
||||
|
||||
jni::global_ref<jobject> localJavaUIManager = getJavaUIManager();
|
||||
if (!localJavaUIManager) {
|
||||
LOG(ERROR) << "Binding::schedulerSetJSResponder: JavaUIManager disappeared";
|
||||
@@ -919,23 +964,25 @@ void Binding::schedulerDidSetJSResponder(
|
||||
|
||||
static auto setJSResponder =
|
||||
jni::findClassStatic(UIManagerJavaDescriptor)
|
||||
->getMethod<void(
|
||||
jint, jint, jboolean)>(
|
||||
"setJSResponder");
|
||||
->getMethod<void(jint, jint, jboolean)>("setJSResponder");
|
||||
|
||||
setJSResponder(localJavaUIManager, shadowView.tag, initialShadowView.tag, (jboolean) blockNativeResponder);
|
||||
setJSResponder(
|
||||
localJavaUIManager,
|
||||
shadowView.tag,
|
||||
initialShadowView.tag,
|
||||
(jboolean)blockNativeResponder);
|
||||
}
|
||||
|
||||
void Binding::schedulerDidClearJSResponder() {
|
||||
jni::global_ref<jobject> localJavaUIManager = getJavaUIManager();
|
||||
if (!localJavaUIManager) {
|
||||
LOG(ERROR) << "Binding::schedulerClearJSResponder: JavaUIManager disappeared";
|
||||
LOG(ERROR)
|
||||
<< "Binding::schedulerClearJSResponder: JavaUIManager disappeared";
|
||||
return;
|
||||
}
|
||||
|
||||
static auto clearJSResponder =
|
||||
jni::findClassStatic(UIManagerJavaDescriptor)
|
||||
->getMethod<void()>("clearJSResponder");
|
||||
static auto clearJSResponder = jni::findClassStatic(UIManagerJavaDescriptor)
|
||||
->getMethod<void()>("clearJSResponder");
|
||||
|
||||
clearJSResponder(localJavaUIManager);
|
||||
}
|
||||
|
||||
@@ -76,17 +76,17 @@ class Binding : public jni::HybridClass<Binding>, public SchedulerDelegate {
|
||||
const ShadowView &shadowView);
|
||||
|
||||
void schedulerDidDispatchCommand(
|
||||
const ShadowView &shadowView,
|
||||
std::string const &commandName,
|
||||
folly::dynamic const args);
|
||||
const ShadowView &shadowView,
|
||||
std::string const &commandName,
|
||||
folly::dynamic const args);
|
||||
|
||||
void setPixelDensity(float pointScaleFactor);
|
||||
|
||||
void schedulerDidSetJSResponder(
|
||||
SurfaceId surfaceId,
|
||||
const ShadowView &shadowView,
|
||||
const ShadowView &initialShadowView,
|
||||
bool blockNativeResponder);
|
||||
SurfaceId surfaceId,
|
||||
const ShadowView &shadowView,
|
||||
const ShadowView &initialShadowView,
|
||||
bool blockNativeResponder);
|
||||
|
||||
void schedulerDidClearJSResponder();
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
#include <fb/fbjni.h>
|
||||
#include <jsi/jsi.h>
|
||||
#include <react/uimanager/ComponentDescriptorRegistry.h>
|
||||
#include <react/utils/ContextContainer.h>
|
||||
#include <react/uimanager/Scheduler.h>
|
||||
#include <react/utils/ContextContainer.h>
|
||||
#include <mutex>
|
||||
#include <unordered_set>
|
||||
|
||||
@@ -25,7 +25,7 @@ class Instance;
|
||||
class ComponentFactoryDelegate
|
||||
: public jni::HybridClass<ComponentFactoryDelegate> {
|
||||
public:
|
||||
constexpr static const char* const kJavaDescriptor =
|
||||
constexpr static const char *const kJavaDescriptor =
|
||||
"Lcom/facebook/react/fabric/ComponentFactoryDelegate;";
|
||||
|
||||
static void registerNatives();
|
||||
|
||||
@@ -13,8 +13,8 @@ namespace facebook {
|
||||
namespace react {
|
||||
|
||||
EventBeatManager::EventBeatManager(
|
||||
jni::alias_ref<EventBeatManager::jhybriddata> jhybridobject)
|
||||
: jhybridobject_(jhybridobject) {}
|
||||
jni::alias_ref<EventBeatManager::jhybriddata> jhybridobject)
|
||||
: jhybridobject_(jhybridobject) {}
|
||||
|
||||
jni::local_ref<EventBeatManager::jhybriddata> EventBeatManager::initHybrid(
|
||||
jni::alias_ref<EventBeatManager::jhybriddata> jhybridobject) {
|
||||
|
||||
@@ -20,7 +20,7 @@ EventEmitterWrapper::initHybrid(jni::alias_ref<jclass>) {
|
||||
|
||||
void EventEmitterWrapper::invokeEvent(
|
||||
std::string eventName,
|
||||
NativeMap* payload) {
|
||||
NativeMap *payload) {
|
||||
eventEmitter->dispatchEvent(
|
||||
eventName, payload->consume(), EventPriority::AsynchronousBatched);
|
||||
}
|
||||
@@ -33,4 +33,4 @@ void EventEmitterWrapper::registerNatives() {
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
} // namespace facebook
|
||||
|
||||
@@ -18,14 +18,14 @@ class Instance;
|
||||
|
||||
class EventEmitterWrapper : public jni::HybridClass<EventEmitterWrapper> {
|
||||
public:
|
||||
constexpr static const char* const kJavaDescriptor =
|
||||
constexpr static const char *const kJavaDescriptor =
|
||||
"Lcom/facebook/react/fabric/events/EventEmitterWrapper;";
|
||||
|
||||
static void registerNatives();
|
||||
|
||||
SharedEventEmitter eventEmitter;
|
||||
|
||||
void invokeEvent(std::string eventName, NativeMap* params);
|
||||
void invokeEvent(std::string eventName, NativeMap *params);
|
||||
|
||||
private:
|
||||
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jclass>);
|
||||
|
||||
@@ -14,8 +14,8 @@ using namespace facebook::jni;
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
jni::local_ref<NodeStateWrapper::jhybriddata>
|
||||
NodeStateWrapper::initHybrid(jni::alias_ref<jclass>) {
|
||||
jni::local_ref<NodeStateWrapper::jhybriddata> NodeStateWrapper::initHybrid(
|
||||
jni::alias_ref<jclass>) {
|
||||
return makeCxxInstance();
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ jni::local_ref<ReadableNativeMap::jhybridobject> NodeStateWrapper::getState() {
|
||||
return readableNativeMap;
|
||||
}
|
||||
|
||||
void NodeStateWrapper::updateState(ReadableNativeMap* map) {
|
||||
void NodeStateWrapper::updateState(ReadableNativeMap *map) {
|
||||
// Get folly::dynamic from map
|
||||
auto dynamicMap = map->consume();
|
||||
// Set state
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace react {
|
||||
|
||||
class NodeStateWrapper : public jni::HybridClass<NodeStateWrapper> {
|
||||
public:
|
||||
constexpr static const char* const kJavaDescriptor =
|
||||
constexpr static const char *const kJavaDescriptor =
|
||||
"Lcom/facebook/react/fabric/NodeStateWrapper;";
|
||||
|
||||
NodeStateWrapper() {}
|
||||
@@ -24,9 +24,10 @@ class NodeStateWrapper : public jni::HybridClass<NodeStateWrapper> {
|
||||
static void registerNatives();
|
||||
|
||||
jni::local_ref<ReadableNativeMap::jhybridobject> getState();
|
||||
void updateState(ReadableNativeMap* map);
|
||||
void updateState(ReadableNativeMap *map);
|
||||
|
||||
const State *state_;
|
||||
|
||||
const State* state_;
|
||||
private:
|
||||
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jclass>);
|
||||
};
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "EventEmitterWrapper.h"
|
||||
#include "StateWrapperImpl.h"
|
||||
|
||||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
|
||||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
|
||||
return facebook::xplat::initialize(vm, [] {
|
||||
facebook::react::Binding::registerNatives();
|
||||
facebook::react::EventBeatManager::registerNatives();
|
||||
|
||||
+4
-4
@@ -11,14 +11,14 @@
|
||||
|
||||
using namespace facebook::react;
|
||||
|
||||
bool ReactNativeConfigHolder::getBool(const std::string& param) const {
|
||||
bool ReactNativeConfigHolder::getBool(const std::string ¶m) const {
|
||||
static const auto method = facebook::jni::findClassStatic(
|
||||
"com/facebook/react/fabric/ReactNativeConfig")
|
||||
->getMethod<jboolean(jstring)>("getBool");
|
||||
return method(reactNativeConfig_, facebook::jni::make_jstring(param).get());
|
||||
}
|
||||
|
||||
std::string ReactNativeConfigHolder::getString(const std::string& param) const {
|
||||
std::string ReactNativeConfigHolder::getString(const std::string ¶m) const {
|
||||
static const auto method = facebook::jni::findClassStatic(
|
||||
"com/facebook/react/fabric/ReactNativeConfig")
|
||||
->getMethod<jstring(jstring)>("getString");
|
||||
@@ -26,14 +26,14 @@ std::string ReactNativeConfigHolder::getString(const std::string& param) const {
|
||||
->toString();
|
||||
}
|
||||
|
||||
int64_t ReactNativeConfigHolder::getInt64(const std::string& param) const {
|
||||
int64_t ReactNativeConfigHolder::getInt64(const std::string ¶m) const {
|
||||
static const auto method = facebook::jni::findClassStatic(
|
||||
"com/facebook/react/fabric/ReactNativeConfig")
|
||||
->getMethod<jint(jstring)>("getInt64");
|
||||
return method(reactNativeConfig_, facebook::jni::make_jstring(param).get());
|
||||
}
|
||||
|
||||
double ReactNativeConfigHolder::getDouble(const std::string& param) const {
|
||||
double ReactNativeConfigHolder::getDouble(const std::string ¶m) const {
|
||||
static const auto method = facebook::jni::findClassStatic(
|
||||
"com/facebook/react/fabric/ReactNativeConfig")
|
||||
->getMethod<jdouble(jstring)>("getDouble");
|
||||
|
||||
@@ -25,10 +25,10 @@ class ReactNativeConfigHolder : public ReactNativeConfig {
|
||||
ReactNativeConfigHolder(jni::alias_ref<jobject> reactNativeConfig)
|
||||
: reactNativeConfig_(make_global(reactNativeConfig)){};
|
||||
|
||||
bool getBool(const std::string& param) const override;
|
||||
std::string getString(const std::string& param) const override;
|
||||
int64_t getInt64(const std::string& param) const override;
|
||||
double getDouble(const std::string& param) const override;
|
||||
bool getBool(const std::string ¶m) const override;
|
||||
std::string getString(const std::string ¶m) const override;
|
||||
int64_t getInt64(const std::string ¶m) const override;
|
||||
double getDouble(const std::string ¶m) const override;
|
||||
|
||||
private:
|
||||
jni::global_ref<jobject> reactNativeConfig_;
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace react {
|
||||
/**
|
||||
* Called from Java constructor through the JNI.
|
||||
*/
|
||||
jni::local_ref<StateWrapperImpl::jhybriddata>
|
||||
StateWrapperImpl::initHybrid(jni::alias_ref<jclass>) {
|
||||
jni::local_ref<StateWrapperImpl::jhybriddata> StateWrapperImpl::initHybrid(
|
||||
jni::alias_ref<jclass>) {
|
||||
return makeCxxInstance();
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ jni::local_ref<ReadableNativeMap::jhybridobject> StateWrapperImpl::getState() {
|
||||
return readableNativeMap;
|
||||
}
|
||||
|
||||
void StateWrapperImpl::updateStateImpl(NativeMap* map) {
|
||||
void StateWrapperImpl::updateStateImpl(NativeMap *map) {
|
||||
// Get folly::dynamic from map
|
||||
auto dynamicMap = map->consume();
|
||||
// Set state
|
||||
@@ -38,8 +38,8 @@ void StateWrapperImpl::updateStateImpl(NativeMap* map) {
|
||||
|
||||
void StateWrapperImpl::registerNatives() {
|
||||
registerHybrid({
|
||||
makeNativeMethod("initHybrid", StateWrapperImpl::initHybrid),
|
||||
makeNativeMethod("getState", StateWrapperImpl::getState),
|
||||
makeNativeMethod("initHybrid", StateWrapperImpl::initHybrid),
|
||||
makeNativeMethod("getState", StateWrapperImpl::getState),
|
||||
makeNativeMethod("updateStateImpl", StateWrapperImpl::updateStateImpl),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ class Instance;
|
||||
|
||||
class StateWrapperImpl : public jni::HybridClass<StateWrapperImpl> {
|
||||
public:
|
||||
constexpr static const char* const kJavaDescriptor =
|
||||
constexpr static const char *const kJavaDescriptor =
|
||||
"Lcom/facebook/react/fabric/StateWrapperImpl;";
|
||||
|
||||
static void registerNatives();
|
||||
@@ -27,6 +27,7 @@ class StateWrapperImpl : public jni::HybridClass<StateWrapperImpl> {
|
||||
void updateStateImpl(NativeMap *map);
|
||||
|
||||
State::Shared state_;
|
||||
|
||||
private:
|
||||
jni::alias_ref<StateWrapperImpl::jhybriddata> jhybridobject_;
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ BlobCollector::BlobCollector(
|
||||
BlobCollector::~BlobCollector() {
|
||||
jni::ThreadScope::WithClassLoader([&] {
|
||||
static auto removeMethod = jni::findClassStatic(kBlobModuleJavaDescriptor)
|
||||
->getMethod<void(jstring)>("remove");
|
||||
->getMethod<void(jstring)>("remove");
|
||||
removeMethod(blobModule_, jni::make_jstring(blobId_).get());
|
||||
});
|
||||
}
|
||||
@@ -36,7 +36,7 @@ void BlobCollector::nativeInstall(
|
||||
jni::alias_ref<jhybridobject> jThis,
|
||||
jni::alias_ref<jobject> blobModule,
|
||||
jlong jsContextNativePointer) {
|
||||
auto &runtime = *((jsi::Runtime *) jsContextNativePointer);
|
||||
auto &runtime = *((jsi::Runtime *)jsContextNativePointer);
|
||||
auto blobModuleRef = jni::make_global(blobModule);
|
||||
runtime.global().setProperty(
|
||||
runtime,
|
||||
|
||||
+2
-3
@@ -7,15 +7,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fb/fbjni.h>
|
||||
#include <ReactCommon/CallInvoker.h>
|
||||
#include <fb/fbjni.h>
|
||||
#include <memory>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class CallInvokerHolder
|
||||
: public jni::HybridClass<CallInvokerHolder> {
|
||||
class CallInvokerHolder : public jni::HybridClass<CallInvokerHolder> {
|
||||
public:
|
||||
static auto constexpr kJavaDescriptor =
|
||||
"Lcom/facebook/react/turbomodule/core/CallInvokerHolderImpl;";
|
||||
|
||||
+2
-1
@@ -12,7 +12,8 @@
|
||||
|
||||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
|
||||
return facebook::xplat::initialize(vm, [] {
|
||||
// TODO: dvacca ramanpreet unify this with the way "ComponentDescriptorFactory" is defined in Fabric
|
||||
// TODO: dvacca ramanpreet unify this with the way
|
||||
// "ComponentDescriptorFactory" is defined in Fabric
|
||||
facebook::react::TurboModuleManager::registerNatives();
|
||||
});
|
||||
}
|
||||
|
||||
+79
-66
@@ -11,8 +11,8 @@
|
||||
#include <fb/fbjni.h>
|
||||
#include <jsi/jsi.h>
|
||||
|
||||
#include <ReactCommon/TurboModuleBinding.h>
|
||||
#include <ReactCommon/TurboCxxModule.h>
|
||||
#include <ReactCommon/TurboModuleBinding.h>
|
||||
#include <react/jni/JMessageQueueThread.h>
|
||||
|
||||
#include "TurboModuleManager.h"
|
||||
@@ -21,37 +21,40 @@ namespace facebook {
|
||||
namespace react {
|
||||
|
||||
TurboModuleManager::TurboModuleManager(
|
||||
jni::alias_ref<TurboModuleManager::javaobject> jThis,
|
||||
jsi::Runtime* rt,
|
||||
std::shared_ptr<CallInvoker> jsCallInvoker,
|
||||
std::shared_ptr<CallInvoker> nativeCallInvoker,
|
||||
jni::alias_ref<TurboModuleManagerDelegate::javaobject> delegate
|
||||
):
|
||||
javaPart_(jni::make_global(jThis)),
|
||||
runtime_(rt),
|
||||
jsCallInvoker_(jsCallInvoker),
|
||||
nativeCallInvoker_(nativeCallInvoker),
|
||||
delegate_(jni::make_global(delegate)),
|
||||
turboModuleCache_(std::make_shared<TurboModuleCache>())
|
||||
{}
|
||||
jni::alias_ref<TurboModuleManager::javaobject> jThis,
|
||||
jsi::Runtime *rt,
|
||||
std::shared_ptr<CallInvoker> jsCallInvoker,
|
||||
std::shared_ptr<CallInvoker> nativeCallInvoker,
|
||||
jni::alias_ref<TurboModuleManagerDelegate::javaobject> delegate)
|
||||
: javaPart_(jni::make_global(jThis)),
|
||||
runtime_(rt),
|
||||
jsCallInvoker_(jsCallInvoker),
|
||||
nativeCallInvoker_(nativeCallInvoker),
|
||||
delegate_(jni::make_global(delegate)),
|
||||
turboModuleCache_(std::make_shared<TurboModuleCache>()) {}
|
||||
|
||||
jni::local_ref<TurboModuleManager::jhybriddata> TurboModuleManager::initHybrid(
|
||||
jni::alias_ref<jhybridobject> jThis,
|
||||
jlong jsContext,
|
||||
jni::alias_ref<CallInvokerHolder::javaobject> jsCallInvokerHolder,
|
||||
jni::alias_ref<CallInvokerHolder::javaobject> nativeCallInvokerHolder,
|
||||
jni::alias_ref<TurboModuleManagerDelegate::javaobject> delegate
|
||||
) {
|
||||
jni::alias_ref<jhybridobject> jThis,
|
||||
jlong jsContext,
|
||||
jni::alias_ref<CallInvokerHolder::javaobject> jsCallInvokerHolder,
|
||||
jni::alias_ref<CallInvokerHolder::javaobject> nativeCallInvokerHolder,
|
||||
jni::alias_ref<TurboModuleManagerDelegate::javaobject> delegate) {
|
||||
auto jsCallInvoker = jsCallInvokerHolder->cthis()->getCallInvoker();
|
||||
auto nativeCallInvoker = nativeCallInvokerHolder->cthis()->getCallInvoker();
|
||||
|
||||
return makeCxxInstance(jThis, (jsi::Runtime *) jsContext, jsCallInvoker, nativeCallInvoker, delegate);
|
||||
return makeCxxInstance(
|
||||
jThis,
|
||||
(jsi::Runtime *)jsContext,
|
||||
jsCallInvoker,
|
||||
nativeCallInvoker,
|
||||
delegate);
|
||||
}
|
||||
|
||||
void TurboModuleManager::registerNatives() {
|
||||
registerHybrid({
|
||||
makeNativeMethod("initHybrid", TurboModuleManager::initHybrid),
|
||||
makeNativeMethod("installJSIBindings", TurboModuleManager::installJSIBindings),
|
||||
makeNativeMethod("initHybrid", TurboModuleManager::initHybrid),
|
||||
makeNativeMethod(
|
||||
"installJSIBindings", TurboModuleManager::installJSIBindings),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -60,57 +63,67 @@ void TurboModuleManager::installJSIBindings() {
|
||||
return; // Runtime doesn't exist when attached to Chrome debugger.
|
||||
}
|
||||
|
||||
TurboModuleBinding::install(*runtime_, std::make_shared<TurboModuleBinding>(
|
||||
[
|
||||
turboModuleCache_ = std::weak_ptr<TurboModuleCache>(turboModuleCache_),
|
||||
jsCallInvoker_ = std::weak_ptr<CallInvoker>(jsCallInvoker_),
|
||||
nativeCallInvoker_ = std::weak_ptr<CallInvoker>(nativeCallInvoker_),
|
||||
delegate_ = jni::make_weak(delegate_),
|
||||
javaPart_ = jni::make_weak(javaPart_)
|
||||
]
|
||||
(const std::string &name) -> std::shared_ptr<TurboModule> {
|
||||
auto turboModuleCache = turboModuleCache_.lock();
|
||||
auto jsCallInvoker = jsCallInvoker_.lock();
|
||||
auto nativeCallInvoker = nativeCallInvoker_.lock();
|
||||
auto delegate = delegate_.lockLocal();
|
||||
auto javaPart = javaPart_.lockLocal();
|
||||
TurboModuleBinding::install(
|
||||
*runtime_,
|
||||
std::make_shared<TurboModuleBinding>(
|
||||
[turboModuleCache_ =
|
||||
std::weak_ptr<TurboModuleCache>(turboModuleCache_),
|
||||
jsCallInvoker_ = std::weak_ptr<CallInvoker>(jsCallInvoker_),
|
||||
nativeCallInvoker_ = std::weak_ptr<CallInvoker>(nativeCallInvoker_),
|
||||
delegate_ = jni::make_weak(delegate_),
|
||||
javaPart_ = jni::make_weak(javaPart_)](
|
||||
const std::string &name) -> std::shared_ptr<TurboModule> {
|
||||
auto turboModuleCache = turboModuleCache_.lock();
|
||||
auto jsCallInvoker = jsCallInvoker_.lock();
|
||||
auto nativeCallInvoker = nativeCallInvoker_.lock();
|
||||
auto delegate = delegate_.lockLocal();
|
||||
auto javaPart = javaPart_.lockLocal();
|
||||
|
||||
if (!turboModuleCache || !jsCallInvoker || !nativeCallInvoker || !delegate || !javaPart) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!turboModuleCache || !jsCallInvoker || !nativeCallInvoker ||
|
||||
!delegate || !javaPart) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto turboModuleLookup = turboModuleCache->find(name);
|
||||
if (turboModuleLookup != turboModuleCache->end()) {
|
||||
return turboModuleLookup->second;
|
||||
}
|
||||
auto turboModuleLookup = turboModuleCache->find(name);
|
||||
if (turboModuleLookup != turboModuleCache->end()) {
|
||||
return turboModuleLookup->second;
|
||||
}
|
||||
|
||||
auto cxxModule = delegate->cthis()->getTurboModule(name, jsCallInvoker);
|
||||
if (cxxModule) {
|
||||
turboModuleCache->insert({name, cxxModule});
|
||||
return cxxModule;
|
||||
}
|
||||
auto cxxModule =
|
||||
delegate->cthis()->getTurboModule(name, jsCallInvoker);
|
||||
if (cxxModule) {
|
||||
turboModuleCache->insert({name, cxxModule});
|
||||
return cxxModule;
|
||||
}
|
||||
|
||||
static auto getLegacyCxxModule = delegate->getClass()->getMethod<jni::alias_ref<CxxModuleWrapper::javaobject>(const std::string&)>("getLegacyCxxModule");
|
||||
auto legacyCxxModule = getLegacyCxxModule(delegate.get(), name);
|
||||
static auto getLegacyCxxModule =
|
||||
delegate->getClass()
|
||||
->getMethod<jni::alias_ref<CxxModuleWrapper::javaobject>(
|
||||
const std::string &)>("getLegacyCxxModule");
|
||||
auto legacyCxxModule = getLegacyCxxModule(delegate.get(), name);
|
||||
|
||||
if (legacyCxxModule) {
|
||||
auto turboModule = std::make_shared<react::TurboCxxModule>(legacyCxxModule->cthis()->getModule(), jsCallInvoker);
|
||||
turboModuleCache->insert({name, turboModule});
|
||||
return turboModule;
|
||||
}
|
||||
if (legacyCxxModule) {
|
||||
auto turboModule = std::make_shared<react::TurboCxxModule>(
|
||||
legacyCxxModule->cthis()->getModule(), jsCallInvoker);
|
||||
turboModuleCache->insert({name, turboModule});
|
||||
return turboModule;
|
||||
}
|
||||
|
||||
static auto getJavaModule = javaPart->getClass()->getMethod<jni::alias_ref<JTurboModule>(const std::string&)>("getJavaModule");
|
||||
auto moduleInstance = getJavaModule(javaPart.get(), name);
|
||||
static auto getJavaModule =
|
||||
javaPart->getClass()
|
||||
->getMethod<jni::alias_ref<JTurboModule>(
|
||||
const std::string &)>("getJavaModule");
|
||||
auto moduleInstance = getJavaModule(javaPart.get(), name);
|
||||
|
||||
if (moduleInstance) {
|
||||
auto turboModule = delegate->cthis()->getTurboModule(name, moduleInstance, jsCallInvoker, nativeCallInvoker);
|
||||
turboModuleCache->insert({name, turboModule});
|
||||
return turboModule;
|
||||
}
|
||||
if (moduleInstance) {
|
||||
auto turboModule = delegate->cthis()->getTurboModule(
|
||||
name, moduleInstance, jsCallInvoker, nativeCallInvoker);
|
||||
turboModuleCache->insert({name, turboModule});
|
||||
return turboModule;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
})
|
||||
);
|
||||
return nullptr;
|
||||
}));
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
|
||||
+24
-23
@@ -7,40 +7,42 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <ReactCommon/CallInvokerHolder.h>
|
||||
#include <ReactCommon/JavaTurboModule.h>
|
||||
#include <ReactCommon/TurboModule.h>
|
||||
#include <ReactCommon/TurboModuleManagerDelegate.h>
|
||||
#include <fb/fbjni.h>
|
||||
#include <jsi/jsi.h>
|
||||
#include <ReactCommon/TurboModule.h>
|
||||
#include <ReactCommon/JavaTurboModule.h>
|
||||
#include <react/jni/CxxModuleWrapper.h>
|
||||
#include <react/jni/JMessageQueueThread.h>
|
||||
#include <ReactCommon/CallInvokerHolder.h>
|
||||
#include <ReactCommon/TurboModuleManagerDelegate.h>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class TurboModuleManager : public jni::HybridClass<TurboModuleManager> {
|
||||
public:
|
||||
static auto constexpr kJavaDescriptor = "Lcom/facebook/react/turbomodule/core/TurboModuleManager;";
|
||||
public:
|
||||
static auto constexpr kJavaDescriptor =
|
||||
"Lcom/facebook/react/turbomodule/core/TurboModuleManager;";
|
||||
static jni::local_ref<jhybriddata> initHybrid(
|
||||
jni::alias_ref<jhybridobject> jThis,
|
||||
jlong jsContext,
|
||||
jni::alias_ref<CallInvokerHolder::javaobject> jsCallInvokerHolder,
|
||||
jni::alias_ref<CallInvokerHolder::javaobject> nativeCallInvokerHolder,
|
||||
jni::alias_ref<TurboModuleManagerDelegate::javaobject> delegate
|
||||
);
|
||||
jni::alias_ref<jhybridobject> jThis,
|
||||
jlong jsContext,
|
||||
jni::alias_ref<CallInvokerHolder::javaobject> jsCallInvokerHolder,
|
||||
jni::alias_ref<CallInvokerHolder::javaobject> nativeCallInvokerHolder,
|
||||
jni::alias_ref<TurboModuleManagerDelegate::javaobject> delegate);
|
||||
static void registerNatives();
|
||||
private:
|
||||
|
||||
private:
|
||||
friend HybridBase;
|
||||
jni::global_ref<TurboModuleManager::javaobject> javaPart_;
|
||||
jsi::Runtime* runtime_;
|
||||
jsi::Runtime *runtime_;
|
||||
std::shared_ptr<CallInvoker> jsCallInvoker_;
|
||||
std::shared_ptr<CallInvoker> nativeCallInvoker_;
|
||||
jni::global_ref<TurboModuleManagerDelegate::javaobject> delegate_;
|
||||
|
||||
using TurboModuleCache = std::unordered_map<std::string, std::shared_ptr<react::TurboModule>>;
|
||||
using TurboModuleCache =
|
||||
std::unordered_map<std::string, std::shared_ptr<react::TurboModule>>;
|
||||
|
||||
/**
|
||||
* TODO(T48018690):
|
||||
@@ -52,12 +54,11 @@ private:
|
||||
|
||||
void installJSIBindings();
|
||||
explicit TurboModuleManager(
|
||||
jni::alias_ref<TurboModuleManager::jhybridobject> jThis,
|
||||
jsi::Runtime *rt,
|
||||
std::shared_ptr<CallInvoker> jsCallInvoker,
|
||||
std::shared_ptr<CallInvoker> nativeCallInvoker,
|
||||
jni::alias_ref<TurboModuleManagerDelegate::javaobject> delegate
|
||||
);
|
||||
jni::alias_ref<TurboModuleManager::jhybridobject> jThis,
|
||||
jsi::Runtime *rt,
|
||||
std::shared_ptr<CallInvoker> jsCallInvoker,
|
||||
std::shared_ptr<CallInvoker> nativeCallInvoker,
|
||||
jni::alias_ref<TurboModuleManagerDelegate::javaobject> delegate);
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
|
||||
+17
-9
@@ -7,23 +7,31 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fb/fbjni.h>
|
||||
#include <ReactCommon/JavaTurboModule.h>
|
||||
#include <ReactCommon/CallInvoker.h>
|
||||
#include <string>
|
||||
#include <ReactCommon/JavaTurboModule.h>
|
||||
#include <fb/fbjni.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class TurboModuleManagerDelegate : public jni::HybridClass<TurboModuleManagerDelegate> {
|
||||
public:
|
||||
static auto constexpr kJavaDescriptor = "Lcom/facebook/react/turbomodule/core/TurboModuleManagerDelegate;";
|
||||
class TurboModuleManagerDelegate
|
||||
: public jni::HybridClass<TurboModuleManagerDelegate> {
|
||||
public:
|
||||
static auto constexpr kJavaDescriptor =
|
||||
"Lcom/facebook/react/turbomodule/core/TurboModuleManagerDelegate;";
|
||||
|
||||
virtual std::shared_ptr<TurboModule> getTurboModule(std::string name, jni::alias_ref<JTurboModule> turboModule, std::shared_ptr<CallInvoker> jsInvoker, std::shared_ptr<CallInvoker> nativeInvoker) = 0;
|
||||
virtual std::shared_ptr<TurboModule> getTurboModule(std::string name, std::shared_ptr<CallInvoker> jsInvoker) = 0;
|
||||
virtual std::shared_ptr<TurboModule> getTurboModule(
|
||||
std::string name,
|
||||
jni::alias_ref<JTurboModule> turboModule,
|
||||
std::shared_ptr<CallInvoker> jsInvoker,
|
||||
std::shared_ptr<CallInvoker> nativeInvoker) = 0;
|
||||
virtual std::shared_ptr<TurboModule> getTurboModule(
|
||||
std::string name,
|
||||
std::shared_ptr<CallInvoker> jsInvoker) = 0;
|
||||
|
||||
private:
|
||||
private:
|
||||
friend HybridBase;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user