Apply clang format to Fabric C++ android code

Summary: run clang-format into Fabric C++ android code

Reviewed By: JoshuaGross

Differential Revision: D14078185

fbshipit-source-id: 07c77044dc7ca437c9dc4417a886f0d8f81ef788
This commit is contained in:
David Vacca 2019-02-14 00:00:59 -08:00 коммит произвёл Facebook Github Bot
Родитель 959fdf6049
Коммит 27a0fc58f7
12 изменённых файлов: 395 добавлений и 251 удалений

Просмотреть файл

@ -4,56 +4,56 @@
#pragma once
#include "EventBeatManager.h"
#include <jsi/jsi.h>
#include <react/events/EventBeat.h>
#include "EventBeatManager.h"
namespace facebook {
namespace react {
namespace {
class AsyncEventBeat:
public EventBeat {
class AsyncEventBeat : public EventBeat {
private:
EventBeatManager* eventBeatManager_;
jsi::Runtime* runtime_;
jni::global_ref<jobject> javaUIManager_;
private:
EventBeatManager *eventBeatManager_;
jsi::Runtime *runtime_;
jni::global_ref<jobject> javaUIManager_;
public:
friend class EventBeatManager;
public:
AsyncEventBeat(
EventBeatManager* eventBeatManager,
jsi::Runtime* runtime,
jni::global_ref<jobject> javaUIManager) {
eventBeatManager_ = eventBeatManager;
runtime_ = runtime;
javaUIManager_ = javaUIManager;
eventBeatManager->registerEventBeat(this);
}
friend class EventBeatManager;
~AsyncEventBeat() {
eventBeatManager_->unregisterEventBeat(this);
}
AsyncEventBeat(EventBeatManager* eventBeatManager, jsi::Runtime *runtime, jni::global_ref<jobject> javaUIManager) {
eventBeatManager_ = eventBeatManager;
runtime_ = runtime;
javaUIManager_ = javaUIManager;
eventBeatManager->registerEventBeat(this);
}
void induce() const override {
beat(*runtime_);
}
~AsyncEventBeat() {
eventBeatManager_->unregisterEventBeat(this);
}
void induce() const override {
beat(*runtime_);
}
void request() const override {
bool alreadyRequested = isRequested_;
EventBeat::request();
if (!alreadyRequested) {
// Notifies java side that an event will be dispatched (e.g. LayoutEvent)
static auto onRequestEventBeat =
jni::findClassStatic("com/facebook/react/fabric/FabricUIManager")
void request() const override {
bool alreadyRequested = isRequested_;
EventBeat::request();
if (!alreadyRequested) {
// Notifies java side that an event will be dispatched (e.g. LayoutEvent)
static auto onRequestEventBeat =
jni::findClassStatic("com/facebook/react/fabric/FabricUIManager")
->getMethod<void()>("onRequestEventBeat");
onRequestEventBeat(javaUIManager_);
}
onRequestEventBeat(javaUIManager_);
}
};
}
};
}
} // namespace
}
}
} // namespace react
} // namespace facebook

Просмотреть файл

@ -2,25 +2,25 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
#include "AsyncEventBeat.h"
#include "Binding.h"
#include "AsyncEventBeat.h"
#include "EventEmitterWrapper.h"
#include "ReactNativeConfigHolder.h"
#include <android/log.h>
#include <fb/fbjni.h>
#include <jsi/jsi.h>
#include <jsi/JSIDynamic.h>
#include <jsi/jsi.h>
#include <react/components/scrollview/ScrollViewProps.h>
#include <react/debug/SystraceSection.h>
#include <react/events/EventEmitter.h>
#include <react/events/EventBeat.h>
#include <react/events/EventEmitter.h>
#include <react/uimanager/ComponentDescriptorFactory.h>
#include <react/uimanager/ContextContainer.h>
#include <react/uimanager/primitives.h>
#include <react/uimanager/Scheduler.h>
#include <react/uimanager/SchedulerDelegate.h>
#include <react/uimanager/TimeUtils.h>
#include <react/uimanager/primitives.h>
using namespace facebook::jni;
using namespace facebook::jsi;
@ -30,20 +30,22 @@ namespace react {
namespace {
struct JMountItem : public JavaClass<JMountItem> {
static constexpr auto kJavaDescriptor = "Lcom/facebook/react/fabric/mounting/mountitems/MountItem;";
};
struct JMountItem : public JavaClass<JMountItem> {
static constexpr auto kJavaDescriptor =
"Lcom/facebook/react/fabric/mounting/mountitems/MountItem;";
};
static constexpr auto UIManagerJavaDescriptor = "com/facebook/react/fabric/FabricUIManager";
static constexpr auto UIManagerJavaDescriptor =
"com/facebook/react/fabric/FabricUIManager";
}
} // namespace
jni::local_ref<Binding::jhybriddata> Binding::initHybrid(
jni::alias_ref<jclass>) {
return makeCxxInstance();
}
void Binding::startSurface(jint surfaceId, NativeMap *initialProps) {
void Binding::startSurface(jint surfaceId, NativeMap* initialProps) {
if (scheduler_) {
scheduler_->startSurface(surfaceId, "", initialProps->consume());
}
@ -52,25 +54,32 @@ void Binding::startSurface(jint surfaceId, NativeMap *initialProps) {
void Binding::renderTemplateToSurface(jint surfaceId, jstring uiTemplate) {
if (scheduler_) {
auto env = Environment::current();
const char *nativeString = env->GetStringUTFChars(uiTemplate, JNI_FALSE);
const char* nativeString = env->GetStringUTFChars(uiTemplate, JNI_FALSE);
scheduler_->renderTemplateToSurface(surfaceId, nativeString);
env->ReleaseStringUTFChars(uiTemplate, nativeString);
}
}
void Binding::stopSurface(jint surfaceId){
void Binding::stopSurface(jint surfaceId) {
if (scheduler_) {
scheduler_->stopSurface(surfaceId);
}
}
void Binding::setConstraints(jint rootTag, jfloat minWidth, jfloat maxWidth, jfloat minHeight, jfloat maxHeight) {
void Binding::setConstraints(
jint rootTag,
jfloat minWidth,
jfloat maxWidth,
jfloat minHeight,
jfloat maxHeight) {
if (scheduler_) {
auto minimumSize = Size {minWidth / pointScaleFactor_, minHeight / pointScaleFactor_};
auto maximumSize = Size {maxWidth / pointScaleFactor_, maxHeight / pointScaleFactor_};
auto minimumSize =
Size{minWidth / pointScaleFactor_, minHeight / pointScaleFactor_};
auto maximumSize =
Size{maxWidth / pointScaleFactor_, maxHeight / pointScaleFactor_};
LayoutContext context;
context.pointScaleFactor = { pointScaleFactor_ };
context.pointScaleFactor = {pointScaleFactor_};
LayoutConstraints constraints = {};
constraints.minimumSize = minimumSize;
constraints.maximumSize = maximumSize;
@ -79,39 +88,58 @@ void Binding::setConstraints(jint rootTag, jfloat minWidth, jfloat maxWidth, jfl
}
}
void Binding::installFabricUIManager(jlong jsContextNativePointer, jni::alias_ref<jobject> javaUIManager, EventBeatManager* eventBeatManager, jni::alias_ref<JavaMessageQueueThread::javaobject> jsMessageQueueThread, ComponentFactoryDelegate* componentsRegistry, jni::alias_ref<jobject> reactNativeConfig) {
Runtime* runtime = (Runtime*) jsContextNativePointer;
void Binding::installFabricUIManager(
jlong jsContextNativePointer,
jni::alias_ref<jobject> javaUIManager,
EventBeatManager* eventBeatManager,
jni::alias_ref<JavaMessageQueueThread::javaobject> jsMessageQueueThread,
ComponentFactoryDelegate* componentsRegistry,
jni::alias_ref<jobject> reactNativeConfig) {
Runtime* runtime = (Runtime*)jsContextNativePointer;
javaUIManager_ = make_global(javaUIManager);
SharedContextContainer contextContainer = std::make_shared<ContextContainer>();
SharedContextContainer contextContainer =
std::make_shared<ContextContainer>();
auto sharedJSMessageQueueThread = std::make_shared<JMessageQueueThread> (jsMessageQueueThread);
RuntimeExecutor runtimeExecutor = [runtime, sharedJSMessageQueueThread](std::function<void(facebook::jsi::Runtime &runtime)> &&callback) {
sharedJSMessageQueueThread->runOnQueue([runtime, callback = std::move(callback)]() {
callback(*runtime);
});
};
auto sharedJSMessageQueueThread =
std::make_shared<JMessageQueueThread>(jsMessageQueueThread);
RuntimeExecutor runtimeExecutor =
[runtime, sharedJSMessageQueueThread](
std::function<void(facebook::jsi::Runtime & runtime)>&& callback) {
sharedJSMessageQueueThread->runOnQueue(
[runtime, callback = std::move(callback)]() {
callback(*runtime);
});
};
// TODO: T31905686 Create synchronous Event Beat
jni::global_ref<jobject> localJavaUIManager = javaUIManager_;
EventBeatFactory synchronousBeatFactory = [eventBeatManager, runtime, localJavaUIManager]() mutable {
return std::make_unique<AsyncEventBeat>(eventBeatManager, runtime, localJavaUIManager);
};
EventBeatFactory synchronousBeatFactory =
[eventBeatManager, runtime, localJavaUIManager]() mutable {
return std::make_unique<AsyncEventBeat>(
eventBeatManager, runtime, localJavaUIManager);
};
EventBeatFactory asynchronousBeatFactory = [eventBeatManager, runtime, localJavaUIManager]() mutable {
return std::make_unique<AsyncEventBeat>(eventBeatManager, runtime, localJavaUIManager);
};
EventBeatFactory asynchronousBeatFactory =
[eventBeatManager, runtime, localJavaUIManager]() mutable {
return std::make_unique<AsyncEventBeat>(
eventBeatManager, runtime, localJavaUIManager);
};
// TODO: Provide non-empty impl for ReactNativeConfig.
std::shared_ptr<const ReactNativeConfig> config = std::make_shared<const ReactNativeConfigHolder>(reactNativeConfig);
std::shared_ptr<const ReactNativeConfig> config =
std::make_shared<const ReactNativeConfigHolder>(reactNativeConfig);
contextContainer->registerInstance(config, "ReactNativeConfig");
contextContainer->registerInstance<EventBeatFactory>(synchronousBeatFactory, "synchronous");
contextContainer->registerInstance<EventBeatFactory>(asynchronousBeatFactory, "asynchronous");
contextContainer->registerInstance<EventBeatFactory>(
synchronousBeatFactory, "synchronous");
contextContainer->registerInstance<EventBeatFactory>(
asynchronousBeatFactory, "asynchronous");
contextContainer->registerInstance(javaUIManager_, "FabricUIManager");
contextContainer->registerInstance(runtimeExecutor, "runtime-executor");
scheduler_ = std::make_shared<Scheduler>(contextContainer, componentsRegistry->buildRegistryFunction);
scheduler_ = std::make_shared<Scheduler>(
contextContainer, componentsRegistry->buildRegistryFunction);
scheduler_->setDelegate(this);
}
@ -121,16 +149,19 @@ void Binding::uninstallFabricUIManager() {
javaUIManager_ = nullptr;
}
inline local_ref<ReadableMap::javaobject> castReadableMap(local_ref<ReadableNativeMap::javaobject> nativeMap) {
inline local_ref<ReadableMap::javaobject> castReadableMap(
local_ref<ReadableNativeMap::javaobject> nativeMap) {
return make_local(reinterpret_cast<ReadableMap::javaobject>(nativeMap.get()));
}
//TODO: this method will be removed when binding for components are code-gen
local_ref<JString> getPlatformComponentName(const ShadowView &shadowView) {
// TODO: this method will be removed when binding for components are code-gen
local_ref<JString> getPlatformComponentName(const ShadowView& shadowView) {
local_ref<JString> componentName;
auto newViewProps = std::dynamic_pointer_cast<const ScrollViewProps>(shadowView.props);
auto newViewProps =
std::dynamic_pointer_cast<const ScrollViewProps>(shadowView.props);
if (newViewProps && newViewProps->yogaStyle.flexDirection == YGFlexDirectionRow) {
if (newViewProps &&
newViewProps->yogaStyle.flexDirection == YGFlexDirectionRow) {
componentName = make_jstring("AndroidHorizontalScrollView");
} else {
componentName = make_jstring(shadowView.componentName);
@ -138,21 +169,33 @@ local_ref<JString> getPlatformComponentName(const ShadowView &shadowView) {
return componentName;
}
local_ref<JMountItem::javaobject> createCreateMountItem(const jni::global_ref<jobject> &javaUIManager, const ShadowViewMutation &mutation, const Tag rootTag) {
local_ref<JMountItem::javaobject> createCreateMountItem(
const jni::global_ref<jobject>& javaUIManager,
const ShadowViewMutation& mutation,
const Tag rootTag) {
static auto createJavaInstruction =
jni::findClassStatic(UIManagerJavaDescriptor)
->getMethod<alias_ref<JMountItem>(jstring,jint,jint,jboolean)>("createMountItem");
jni::findClassStatic(UIManagerJavaDescriptor)
->getMethod<alias_ref<JMountItem>(jstring, jint, jint, jboolean)>(
"createMountItem");
auto newChildShadowView = mutation.newChildShadowView;
local_ref<JString> componentName = getPlatformComponentName(newChildShadowView);
local_ref<JString> componentName =
getPlatformComponentName(newChildShadowView);
jboolean isVirtual = newChildShadowView.layoutMetrics == EmptyLayoutMetrics;
return createJavaInstruction(javaUIManager, componentName.get(), rootTag, newChildShadowView.tag, isVirtual);
return createJavaInstruction(
javaUIManager,
componentName.get(),
rootTag,
newChildShadowView.tag,
isVirtual);
}
local_ref<JMountItem::javaobject> createUpdateEventEmitterMountItem(const jni::global_ref<jobject> &javaUIManager, const ShadowViewMutation &mutation) {
local_ref<JMountItem::javaobject> createUpdateEventEmitterMountItem(
const jni::global_ref<jobject>& javaUIManager,
const ShadowViewMutation& mutation) {
if (!mutation.newChildShadowView.eventEmitter) {
return nullptr;
}
@ -164,37 +207,47 @@ local_ref<JMountItem::javaobject> createUpdateEventEmitterMountItem(const jni::g
cEventEmitter->eventEmitter = eventEmitter;
static auto updateEventEmitterInstruction =
jni::findClassStatic(UIManagerJavaDescriptor)
->getMethod<alias_ref<JMountItem>(jint, jobject)>("updateEventEmitterMountItem");
jni::findClassStatic(UIManagerJavaDescriptor)
->getMethod<alias_ref<JMountItem>(jint, jobject)>(
"updateEventEmitterMountItem");
return updateEventEmitterInstruction(javaUIManager, mutation.newChildShadowView.tag, javaEventEmitter.get());
return updateEventEmitterInstruction(
javaUIManager, mutation.newChildShadowView.tag, javaEventEmitter.get());
}
local_ref<JMountItem::javaobject> createUpdatePropsMountItem(const jni::global_ref<jobject> &javaUIManager, const ShadowViewMutation &mutation) {
local_ref<JMountItem::javaobject> createUpdatePropsMountItem(
const jni::global_ref<jobject>& javaUIManager,
const ShadowViewMutation& mutation) {
auto shadowView = mutation.newChildShadowView;
auto newViewProps = *std::dynamic_pointer_cast<const ViewProps>(shadowView.props);
auto newViewProps =
*std::dynamic_pointer_cast<const ViewProps>(shadowView.props);
// TODO: move props from map to a typed object.
auto newProps = shadowView.props->rawProps;
local_ref<ReadableMap::javaobject> readableMap = castReadableMap(ReadableNativeMap::newObjectCxxArgs(newProps));
local_ref<ReadableMap::javaobject> readableMap =
castReadableMap(ReadableNativeMap::newObjectCxxArgs(newProps));
static auto updatePropsInstruction =
jni::findClassStatic(UIManagerJavaDescriptor)
->getMethod<alias_ref<JMountItem>(jint,ReadableMap::javaobject)>("updatePropsMountItem");
jni::findClassStatic(UIManagerJavaDescriptor)
->getMethod<alias_ref<JMountItem>(jint, ReadableMap::javaobject)>(
"updatePropsMountItem");
return updatePropsInstruction(javaUIManager,
mutation.newChildShadowView.tag,
readableMap.get());
return updatePropsInstruction(
javaUIManager, mutation.newChildShadowView.tag, readableMap.get());
}
local_ref<JMountItem::javaobject> createUpdateLayoutMountItem(const jni::global_ref<jobject> &javaUIManager, const ShadowViewMutation &mutation) {
local_ref<JMountItem::javaobject> createUpdateLayoutMountItem(
const jni::global_ref<jobject>& javaUIManager,
const ShadowViewMutation& mutation) {
auto oldChildShadowView = mutation.oldChildShadowView;
auto newChildShadowView = mutation.newChildShadowView;
if (newChildShadowView.layoutMetrics != EmptyLayoutMetrics && oldChildShadowView.layoutMetrics != newChildShadowView.layoutMetrics) {
if (newChildShadowView.layoutMetrics != EmptyLayoutMetrics &&
oldChildShadowView.layoutMetrics != newChildShadowView.layoutMetrics) {
static auto updateLayoutInstruction =
jni::findClassStatic(UIManagerJavaDescriptor)
->getMethod<alias_ref<JMountItem>(jint, jint, jint, jint, jint)>("updateLayoutMountItem");
jni::findClassStatic(UIManagerJavaDescriptor)
->getMethod<alias_ref<JMountItem>(jint, jint, jint, jint, jint)>(
"updateLayoutMountItem");
auto layoutMetrics = newChildShadowView.layoutMetrics;
auto pointScaleFactor = layoutMetrics.pointScaleFactor;
auto frame = layoutMetrics.frame;
@ -203,24 +256,35 @@ local_ref<JMountItem::javaobject> createUpdateLayoutMountItem(const jni::global_
int y = round(frame.origin.y * pointScaleFactor);
int w = round(frame.size.width * pointScaleFactor);
int h = round(frame.size.height * pointScaleFactor);
return updateLayoutInstruction(javaUIManager, newChildShadowView.tag, x, y, w, h);
return updateLayoutInstruction(
javaUIManager, newChildShadowView.tag, x, y, w, h);
}
return nullptr;
}
local_ref<JMountItem::javaobject> createInsertMountItem(const jni::global_ref<jobject> &javaUIManager, const ShadowViewMutation &mutation) {
local_ref<JMountItem::javaobject> createInsertMountItem(
const jni::global_ref<jobject>& javaUIManager,
const ShadowViewMutation& mutation) {
static auto insertInstruction =
jni::findClassStatic(UIManagerJavaDescriptor)
->getMethod<alias_ref<JMountItem>(jint,jint,jint)>("insertMountItem");
jni::findClassStatic(UIManagerJavaDescriptor)
->getMethod<alias_ref<JMountItem>(jint, jint, jint)>(
"insertMountItem");
return insertInstruction(javaUIManager, mutation.newChildShadowView.tag, mutation.parentShadowView.tag, mutation.index);
return insertInstruction(
javaUIManager,
mutation.newChildShadowView.tag,
mutation.parentShadowView.tag,
mutation.index);
}
local_ref<JMountItem::javaobject> createUpdateLocalData(const jni::global_ref<jobject> &javaUIManager, const ShadowViewMutation &mutation) {
local_ref<JMountItem::javaobject> createUpdateLocalData(
const jni::global_ref<jobject>& javaUIManager,
const ShadowViewMutation& mutation) {
static auto updateLocalDataInstruction =
jni::findClassStatic(UIManagerJavaDescriptor)
->getMethod<alias_ref<JMountItem>(jint, ReadableMap::javaobject)>("updateLocalDataMountItem");
jni::findClassStatic(UIManagerJavaDescriptor)
->getMethod<alias_ref<JMountItem>(jint, ReadableMap::javaobject)>(
"updateLocalDataMountItem");
auto localData = mutation.newChildShadowView.localData;
@ -229,27 +293,44 @@ local_ref<JMountItem::javaobject> createUpdateLocalData(const jni::global_ref<jo
newLocalData = localData->getDynamic();
}
local_ref<ReadableNativeMap::jhybridobject> readableNativeMap = ReadableNativeMap::newObjectCxxArgs(newLocalData);
return updateLocalDataInstruction(javaUIManager, mutation.newChildShadowView.tag, castReadableMap(readableNativeMap).get());
local_ref<ReadableNativeMap::jhybridobject> readableNativeMap =
ReadableNativeMap::newObjectCxxArgs(newLocalData);
return updateLocalDataInstruction(
javaUIManager,
mutation.newChildShadowView.tag,
castReadableMap(readableNativeMap).get());
}
local_ref<JMountItem::javaobject> createRemoveMountItem(const jni::global_ref<jobject> &javaUIManager, const ShadowViewMutation &mutation) {
local_ref<JMountItem::javaobject> createRemoveMountItem(
const jni::global_ref<jobject>& javaUIManager,
const ShadowViewMutation& mutation) {
static auto removeInstruction =
jni::findClassStatic(UIManagerJavaDescriptor)
->getMethod<alias_ref<JMountItem>(jint,jint,jint)>("removeMountItem");
jni::findClassStatic(UIManagerJavaDescriptor)
->getMethod<alias_ref<JMountItem>(jint, jint, jint)>(
"removeMountItem");
return removeInstruction(javaUIManager, mutation.oldChildShadowView.tag, mutation.parentShadowView.tag, mutation.index);
return removeInstruction(
javaUIManager,
mutation.oldChildShadowView.tag,
mutation.parentShadowView.tag,
mutation.index);
}
local_ref<JMountItem::javaobject> createDeleteMountItem(const jni::global_ref<jobject> &javaUIManager, const ShadowViewMutation &mutation) {
local_ref<JMountItem::javaobject> createDeleteMountItem(
const jni::global_ref<jobject>& javaUIManager,
const ShadowViewMutation& mutation) {
static auto deleteInstruction =
jni::findClassStatic(UIManagerJavaDescriptor)
->getMethod<alias_ref<JMountItem>(jint)>("deleteMountItem");
jni::findClassStatic(UIManagerJavaDescriptor)
->getMethod<alias_ref<JMountItem>(jint)>("deleteMountItem");
return deleteInstruction(javaUIManager, mutation.oldChildShadowView.tag);
}
void Binding::schedulerDidFinishTransaction(const Tag rootTag, const ShadowViewMutationList &mutations, const long commitStartTime, const long layoutTime) {
void Binding::schedulerDidFinishTransaction(
const Tag rootTag,
const ShadowViewMutationList& mutations,
const long commitStartTime,
const long layoutTime) {
SystraceSection s("FabricUIManager::schedulerDidFinishTransaction");
std::vector<local_ref<jobject>> queue;
// Upper bound estimation of mount items to be delivered to Java side.
@ -257,13 +338,13 @@ void Binding::schedulerDidFinishTransaction(const Tag rootTag, const ShadowViewM
long finishTransactionStartTime = getTime();
local_ref<JArrayClass<JMountItem::javaobject>> mountItemsArray = JArrayClass<JMountItem::javaobject>::newArray(size);
local_ref<JArrayClass<JMountItem::javaobject>> mountItemsArray =
JArrayClass<JMountItem::javaobject>::newArray(size);
auto mountItems = *(mountItemsArray);
int position = 0;
for (const auto &mutation : mutations) {
for (const auto& mutation : mutations) {
auto oldChildShadowView = mutation.oldChildShadowView;
auto newChildShadowView = mutation.newChildShadowView;
@ -272,36 +353,46 @@ void Binding::schedulerDidFinishTransaction(const Tag rootTag, const ShadowViewM
switch (mutation.type) {
case ShadowViewMutation::Create: {
mountItems[position++] = createCreateMountItem(javaUIManager_, mutation, rootTag);
mountItems[position++] =
createCreateMountItem(javaUIManager_, mutation, rootTag);
break;
}
case ShadowViewMutation::Remove: {
if (!isVirtual) {
mountItems[position++] = createRemoveMountItem(javaUIManager_, mutation);
mountItems[position++] =
createRemoveMountItem(javaUIManager_, mutation);
}
break;
}
case ShadowViewMutation::Delete: {
mountItems[position++] = createDeleteMountItem(javaUIManager_, mutation);
mountItems[position++] =
createDeleteMountItem(javaUIManager_, mutation);
break;
}
case ShadowViewMutation::Update: {
if (!isVirtual) {
if (mutation.oldChildShadowView.props != mutation.newChildShadowView.props) {
mountItems[position++] = createUpdatePropsMountItem(javaUIManager_, mutation);
if (mutation.oldChildShadowView.props !=
mutation.newChildShadowView.props) {
mountItems[position++] =
createUpdatePropsMountItem(javaUIManager_, mutation);
}
if (mutation.oldChildShadowView.localData != mutation.newChildShadowView.localData) {
mountItems[position++] = createUpdateLocalData(javaUIManager_, mutation);
if (mutation.oldChildShadowView.localData !=
mutation.newChildShadowView.localData) {
mountItems[position++] =
createUpdateLocalData(javaUIManager_, mutation);
}
auto updateLayoutMountItem = createUpdateLayoutMountItem(javaUIManager_, mutation);
auto updateLayoutMountItem =
createUpdateLayoutMountItem(javaUIManager_, mutation);
if (updateLayoutMountItem) {
mountItems[position++] = updateLayoutMountItem;
}
}
if (mutation.oldChildShadowView.eventEmitter != mutation.newChildShadowView.eventEmitter) {
auto updateEventEmitterMountItem = createUpdateEventEmitterMountItem(javaUIManager_, mutation);
if (mutation.oldChildShadowView.eventEmitter !=
mutation.newChildShadowView.eventEmitter) {
auto updateEventEmitterMountItem =
createUpdateEventEmitterMountItem(javaUIManager_, mutation);
if (updateEventEmitterMountItem) {
mountItems[position++] = updateEventEmitterMountItem;
}
@ -310,21 +401,26 @@ void Binding::schedulerDidFinishTransaction(const Tag rootTag, const ShadowViewM
}
case ShadowViewMutation::Insert: {
if (!isVirtual) {
mountItems[position++] = createInsertMountItem(javaUIManager_, mutation);
mountItems[position++] =
createInsertMountItem(javaUIManager_, mutation);
mountItems[position++] = createUpdatePropsMountItem(javaUIManager_, mutation);
mountItems[position++] =
createUpdatePropsMountItem(javaUIManager_, mutation);
auto updateLayoutMountItem = createUpdateLayoutMountItem(javaUIManager_, mutation);
auto updateLayoutMountItem =
createUpdateLayoutMountItem(javaUIManager_, mutation);
if (updateLayoutMountItem) {
mountItems[position++] = updateLayoutMountItem;
}
if (mutation.newChildShadowView.localData) {
mountItems[position++] = createUpdateLocalData(javaUIManager_, mutation);
mountItems[position++] =
createUpdateLocalData(javaUIManager_, mutation);
}
}
auto updateEventEmitterMountItem = createUpdateEventEmitterMountItem(javaUIManager_, mutation);
auto updateEventEmitterMountItem =
createUpdateEventEmitterMountItem(javaUIManager_, mutation);
if (updateEventEmitterMountItem) {
mountItems[position++] = updateEventEmitterMountItem;
}
@ -337,44 +433,60 @@ void Binding::schedulerDidFinishTransaction(const Tag rootTag, const ShadowViewM
}
static auto createMountItemsBatchContainer =
jni::findClassStatic(UIManagerJavaDescriptor)
->getMethod<alias_ref<JMountItem>(jtypeArray<JMountItem::javaobject>,jint)>("createBatchMountItem");
jni::findClassStatic(UIManagerJavaDescriptor)
->getMethod<alias_ref<JMountItem>(
jtypeArray<JMountItem::javaobject>, jint)>(
"createBatchMountItem");
auto batch = createMountItemsBatchContainer(javaUIManager_, mountItemsArray.get(), position);
auto batch = createMountItemsBatchContainer(
javaUIManager_, mountItemsArray.get(), position);
static auto scheduleMountItems =
jni::findClassStatic(UIManagerJavaDescriptor)
->getMethod<void(JMountItem::javaobject,jlong,jlong,jlong)>("scheduleMountItems");
jni::findClassStatic(UIManagerJavaDescriptor)
->getMethod<void(JMountItem::javaobject, jlong, jlong, jlong)>(
"scheduleMountItems");
scheduleMountItems(javaUIManager_, batch.get(), commitStartTime, layoutTime, finishTransactionStartTime);
scheduleMountItems(
javaUIManager_,
batch.get(),
commitStartTime,
layoutTime,
finishTransactionStartTime);
}
void Binding::setPixelDensity(float pointScaleFactor) {
pointScaleFactor_ = pointScaleFactor;
}
void Binding::schedulerDidRequestPreliminaryViewAllocation(const SurfaceId surfaceId, const ComponentName componentName, bool isLayoutable, const ComponentHandle componentHandle) {
void Binding::schedulerDidRequestPreliminaryViewAllocation(
const SurfaceId surfaceId,
const ComponentName componentName,
bool isLayoutable,
const ComponentHandle componentHandle) {
if (isLayoutable) {
static auto preallocateView =
jni::findClassStatic(UIManagerJavaDescriptor)
->getMethod<void(jint,jstring)>("preallocateView");
jni::findClassStatic(UIManagerJavaDescriptor)
->getMethod<void(jint, jstring)>("preallocateView");
preallocateView(javaUIManager_, surfaceId, make_jstring(componentName).get());
preallocateView(
javaUIManager_, surfaceId, make_jstring(componentName).get());
}
}
void Binding::registerNatives() {
registerHybrid({
makeNativeMethod("initHybrid", Binding::initHybrid),
makeNativeMethod("installFabricUIManager", Binding::installFabricUIManager),
makeNativeMethod("startSurface", Binding::startSurface),
makeNativeMethod("renderTemplateToSurface", Binding::renderTemplateToSurface),
makeNativeMethod("stopSurface", Binding::stopSurface),
makeNativeMethod("setConstraints", Binding::setConstraints),
makeNativeMethod("setPixelDensity", Binding::setPixelDensity),
makeNativeMethod("uninstallFabricUIManager", Binding::uninstallFabricUIManager)
});
registerHybrid(
{makeNativeMethod("initHybrid", Binding::initHybrid),
makeNativeMethod(
"installFabricUIManager", Binding::installFabricUIManager),
makeNativeMethod("startSurface", Binding::startSurface),
makeNativeMethod(
"renderTemplateToSurface", Binding::renderTemplateToSurface),
makeNativeMethod("stopSurface", Binding::stopSurface),
makeNativeMethod("setConstraints", Binding::setConstraints),
makeNativeMethod("setPixelDensity", Binding::setPixelDensity),
makeNativeMethod(
"uninstallFabricUIManager", Binding::uninstallFabricUIManager)});
}
}
}
} // namespace react
} // namespace facebook

Просмотреть файл

@ -4,15 +4,15 @@
#pragma once
#include "ComponentFactoryDelegate.h"
#include "EventBeatManager.h"
#include <memory>
#include <fb/fbjni.h>
#include <react/jni/JMessageQueueThread.h>
#include <react/jni/ReadableNativeMap.h>
#include <react/uimanager/Scheduler.h>
#include <react/uimanager/SchedulerDelegate.h>
#include <memory>
#include <mutex>
#include "ComponentFactoryDelegate.h"
#include "EventBeatManager.h"
namespace facebook {
namespace react {
@ -20,9 +20,9 @@ namespace react {
class Instance;
class Binding : public jni::HybridClass<Binding>, public SchedulerDelegate {
public:
constexpr static const char *const kJavaDescriptor =
"Lcom/facebook/react/fabric/jsi/Binding;";
public:
constexpr static const char* const kJavaDescriptor =
"Lcom/facebook/react/fabric/jsi/Binding;";
static void registerNatives();
@ -32,29 +32,46 @@ public:
float pointScaleFactor_ = 1;
private:
void setConstraints(jint rootTag, jfloat minWidth, jfloat maxWidth, jfloat minHeight, jfloat maxHeight);
private:
void setConstraints(
jint rootTag,
jfloat minWidth,
jfloat maxWidth,
jfloat minHeight,
jfloat maxHeight);
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jclass>);
void installFabricUIManager(jlong jsContextNativePointer, jni::alias_ref<jobject> javaUIManager, EventBeatManager* eventBeatManager, jni::alias_ref<JavaMessageQueueThread::javaobject> jsMessageQueueThread, ComponentFactoryDelegate* componentsRegistry, jni::alias_ref<jobject> reactNativeConfig);
void installFabricUIManager(
jlong jsContextNativePointer,
jni::alias_ref<jobject> javaUIManager,
EventBeatManager* eventBeatManager,
jni::alias_ref<JavaMessageQueueThread::javaobject> jsMessageQueueThread,
ComponentFactoryDelegate* componentsRegistry,
jni::alias_ref<jobject> reactNativeConfig);
void startSurface(jint surfaceId, NativeMap *initialProps);
void startSurface(jint surfaceId, NativeMap* initialProps);
void renderTemplateToSurface(jint surfaceId, jstring uiTemplate);
void stopSurface(jint surfaceId);
void schedulerDidFinishTransaction(const Tag rootTag, const ShadowViewMutationList &mutations, const long commitStartTime, const long layoutTime);
void schedulerDidFinishTransaction(
const Tag rootTag,
const ShadowViewMutationList& mutations,
const long commitStartTime,
const long layoutTime);
void schedulerDidRequestPreliminaryViewAllocation(const SurfaceId surfaceId, const ComponentName componentName, bool isLayoutable, const ComponentHandle componentHandle);
void schedulerDidRequestPreliminaryViewAllocation(
const SurfaceId surfaceId,
const ComponentName componentName,
bool isLayoutable,
const ComponentHandle componentHandle);
void setPixelDensity(float pointScaleFactor);
void uninstallFabricUIManager();
};
}
}
} // namespace react
} // namespace facebook

Просмотреть файл

@ -4,24 +4,25 @@
#include "ComponentFactoryDelegate.h"
#include <android/log.h>
#include <react/uimanager/ComponentDescriptorRegistry.h>
#include <fb/fbjni.h>
#include <jsi/jsi.h>
#include <react/uimanager/ComponentDescriptorRegistry.h>
using namespace facebook::jsi;
namespace facebook {
namespace react {
jni::local_ref<ComponentFactoryDelegate::jhybriddata> ComponentFactoryDelegate::initHybrid(
jni::alias_ref<jclass>) {
jni::local_ref<ComponentFactoryDelegate::jhybriddata>
ComponentFactoryDelegate::initHybrid(jni::alias_ref<jclass>) {
return makeCxxInstance();
}
void ComponentFactoryDelegate::registerNatives() {
registerHybrid({
makeNativeMethod("initHybrid", ComponentFactoryDelegate::initHybrid),
makeNativeMethod("initHybrid", ComponentFactoryDelegate::initHybrid),
});
}
}}
} // namespace react
} // namespace facebook

Просмотреть файл

@ -4,11 +4,11 @@
#pragma once
#include <fb/fbjni.h>
#include <jsi/jsi.h>
#include <react/uimanager/ComponentDescriptorRegistry.h>
#include <react/uimanager/ContextContainer.h>
#include <react/uimanager/Scheduler.h>
#include <fb/fbjni.h>
#include <jsi/jsi.h>
#include <mutex>
#include <unordered_set>
@ -19,20 +19,19 @@ namespace react {
class Instance;
class ComponentFactoryDelegate : public jni::HybridClass<ComponentFactoryDelegate> {
public:
constexpr static const char *const kJavaDescriptor =
"Lcom/facebook/react/fabric/jsi/ComponentFactoryDelegate;";
class ComponentFactoryDelegate
: public jni::HybridClass<ComponentFactoryDelegate> {
public:
constexpr static const char* const kJavaDescriptor =
"Lcom/facebook/react/fabric/jsi/ComponentFactoryDelegate;";
static void registerNatives();
ComponentRegistryFactory buildRegistryFunction;
private:
private:
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jclass>);
};
}
}
} // namespace react
} // namespace facebook

Просмотреть файл

@ -9,20 +9,24 @@ using namespace facebook::jni;
namespace facebook {
namespace react {
EventBeatManager::EventBeatManager(Runtime* runtime, jni::alias_ref<EventBeatManager::jhybriddata> jhybridobject) : runtime_(runtime), jhybridobject_(jhybridobject) { }
EventBeatManager::EventBeatManager(
Runtime* runtime,
jni::alias_ref<EventBeatManager::jhybriddata> jhybridobject)
: runtime_(runtime), jhybridobject_(jhybridobject) {}
jni::local_ref<EventBeatManager::jhybriddata> EventBeatManager::initHybrid(
jni::alias_ref<EventBeatManager::jhybriddata> jhybridobject, jlong jsContext) {
return makeCxxInstance((Runtime *) jsContext, jhybridobject);
jni::alias_ref<EventBeatManager::jhybriddata> jhybridobject,
jlong jsContext) {
return makeCxxInstance((Runtime*)jsContext, jhybridobject);
}
void EventBeatManager::registerEventBeat(EventBeat *eventBeat) const {
void EventBeatManager::registerEventBeat(EventBeat* eventBeat) const {
std::lock_guard<std::mutex> lock(mutex_);
registeredEventBeats_.insert(eventBeat);
}
void EventBeatManager::unregisterEventBeat(EventBeat *eventBeat) const {
void EventBeatManager::unregisterEventBeat(EventBeat* eventBeat) const {
std::lock_guard<std::mutex> lock(mutex_);
registeredEventBeats_.erase(eventBeat);
@ -38,10 +42,10 @@ void EventBeatManager::beat() {
void EventBeatManager::registerNatives() {
registerHybrid({
makeNativeMethod("initHybrid", EventBeatManager::initHybrid),
makeNativeMethod("beat", EventBeatManager::beat),
makeNativeMethod("initHybrid", EventBeatManager::initHybrid),
makeNativeMethod("beat", EventBeatManager::beat),
});
}
}
}
} // namespace react
} // namespace facebook

Просмотреть файл

@ -4,9 +4,9 @@
#pragma once
#include <react/events/EventBeat.h>
#include <fb/fbjni.h>
#include <jsi/jsi.h>
#include <react/events/EventBeat.h>
#include <mutex>
#include <unordered_set>
@ -18,33 +18,36 @@ namespace react {
class Instance;
class EventBeatManager : public jni::HybridClass<EventBeatManager> {
public:
constexpr static const char *const kJavaDescriptor =
"Lcom/facebook/react/fabric/jsi/EventBeatManager;";
public:
constexpr static const char* const kJavaDescriptor =
"Lcom/facebook/react/fabric/jsi/EventBeatManager;";
static void registerNatives();
void registerEventBeat(EventBeat *eventBeat) const;
void registerEventBeat(EventBeat* eventBeat) const;
void unregisterEventBeat(EventBeat *eventBeat) const;
void unregisterEventBeat(EventBeat* eventBeat) const;
void beat();
EventBeatManager(Runtime* runtime, jni::alias_ref<EventBeatManager::jhybriddata> jhybridobject);
private:
EventBeatManager(
Runtime* runtime,
jni::alias_ref<EventBeatManager::jhybriddata> jhybridobject);
private:
Runtime* runtime_;
jni::alias_ref<EventBeatManager::jhybriddata> jhybridobject_;
mutable std::unordered_set<const EventBeat *> registeredEventBeats_ {}; // Protected by `mutex_`
mutable std::unordered_set<const EventBeat*>
registeredEventBeats_{}; // Protected by `mutex_`
mutable std::mutex mutex_;
static jni::local_ref<EventBeatManager::jhybriddata> initHybrid(jni::alias_ref<EventBeatManager::jhybriddata> jhybridobject, jlong jsContext);
static jni::local_ref<EventBeatManager::jhybriddata> initHybrid(
jni::alias_ref<EventBeatManager::jhybriddata> jhybridobject,
jlong jsContext);
};
}
}
} // namespace react
} // namespace facebook

Просмотреть файл

@ -10,21 +10,24 @@ using namespace facebook::jni;
namespace facebook {
namespace react {
jni::local_ref<EventEmitterWrapper::jhybriddata> EventEmitterWrapper::initHybrid(
jni::alias_ref<jclass>) {
jni::local_ref<EventEmitterWrapper::jhybriddata>
EventEmitterWrapper::initHybrid(jni::alias_ref<jclass>) {
return makeCxxInstance();
}
void EventEmitterWrapper::invokeEvent(std::string eventName, NativeMap *payload) {
eventEmitter->dispatchEvent(eventName, payload->consume(), EventPriority::AsynchronousBatched);
void EventEmitterWrapper::invokeEvent(
std::string eventName,
NativeMap* payload) {
eventEmitter->dispatchEvent(
eventName, payload->consume(), EventPriority::AsynchronousBatched);
}
void EventEmitterWrapper::registerNatives() {
registerHybrid({
makeNativeMethod("initHybrid", EventEmitterWrapper::initHybrid),
makeNativeMethod("invokeEvent", EventEmitterWrapper::invokeEvent),
makeNativeMethod("initHybrid", EventEmitterWrapper::initHybrid),
makeNativeMethod("invokeEvent", EventEmitterWrapper::invokeEvent),
});
}
}
}
} // namespace react
} // namespace facebook

Просмотреть файл

@ -14,21 +14,19 @@ namespace react {
class Instance;
class EventEmitterWrapper : public jni::HybridClass<EventEmitterWrapper> {
public:
constexpr static const char *const kJavaDescriptor =
"Lcom/facebook/react/fabric/jsi/EventEmitterWrapper;";
public:
constexpr static const char* const kJavaDescriptor =
"Lcom/facebook/react/fabric/jsi/EventEmitterWrapper;";
static void registerNatives();
SharedEventEmitter eventEmitter;
void invokeEvent(std::string eventName, NativeMap *params);
private:
void invokeEvent(std::string eventName, NativeMap* params);
private:
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jclass>);
};
}
}
} // namespace react
} // namespace facebook

Просмотреть файл

@ -10,7 +10,7 @@
#include "EventBeatManager.h"
#include "EventEmitterWrapper.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();

Просмотреть файл

@ -11,26 +11,31 @@
using namespace facebook::react;
bool ReactNativeConfigHolder::getBool(const std::string &param) const {
static const auto method = facebook::jni::findClassStatic("com/facebook/react/fabric/ReactNativeConfig")
->getMethod<jboolean(jstring)>("getBool");
bool ReactNativeConfigHolder::getBool(const std::string& param) 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 {
static const auto method = facebook::jni::findClassStatic("com/facebook/react/fabric/ReactNativeConfig")
->getMethod<jstring(jstring)>("getString");
return method(reactNativeConfig_, facebook::jni::make_jstring(param).get())->toString();
std::string ReactNativeConfigHolder::getString(const std::string& param) const {
static const auto method = facebook::jni::findClassStatic(
"com/facebook/react/fabric/ReactNativeConfig")
->getMethod<jstring(jstring)>("getString");
return method(reactNativeConfig_, facebook::jni::make_jstring(param).get())
->toString();
}
int64_t ReactNativeConfigHolder::getInt64(const std::string &param) const {
static const auto method = facebook::jni::findClassStatic("com/facebook/react/fabric/ReactNativeConfig")
->getMethod<jint(jstring)>("getInt64");
int64_t ReactNativeConfigHolder::getInt64(const std::string& param) 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 {
static const auto method = facebook::jni::findClassStatic("com/facebook/react/fabric/ReactNativeConfig")
->getMethod<jdouble(jstring)>("getDouble");
double ReactNativeConfigHolder::getDouble(const std::string& param) const {
static const auto method = facebook::jni::findClassStatic(
"com/facebook/react/fabric/ReactNativeConfig")
->getMethod<jdouble(jstring)>("getDouble");
return method(reactNativeConfig_, facebook::jni::make_jstring(param).get());
}

Просмотреть файл

@ -7,28 +7,30 @@
#pragma once
#include <memory>
#include <fb/fbjni.h>
#include <react/config/ReactNativeConfig.h>
#include <react/jni/JMessageQueueThread.h>
#include <react/jni/ReadableNativeMap.h>
#include <react/config/ReactNativeConfig.h>
#include <memory>
namespace facebook {
namespace react {
/**
* Implementation of ReactNativeConfig that wraps a FabricMobileConfig Java object.
* Implementation of ReactNativeConfig that wraps a FabricMobileConfig Java
* object.
*/
class ReactNativeConfigHolder : public ReactNativeConfig {
public:
ReactNativeConfigHolder(jni::alias_ref<jobject> reactNativeConfig) : reactNativeConfig_(reactNativeConfig) {};
public:
ReactNativeConfigHolder(jni::alias_ref<jobject> reactNativeConfig)
: reactNativeConfig_(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& 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;
private:
private:
jni::alias_ref<jobject> reactNativeConfig_;
};