From 27a0fc58f7dad02b1b465473eddafb1483060664 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Thu, 14 Feb 2019 00:00:59 -0800 Subject: [PATCH] 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 --- .../react/fabric/jsi/jni/AsyncEventBeat.h | 72 ++-- .../facebook/react/fabric/jsi/jni/Binding.cpp | 350 ++++++++++++------ .../facebook/react/fabric/jsi/jni/Binding.h | 49 ++- .../jsi/jni/ComponentFactoryDelegate.cpp | 11 +- .../fabric/jsi/jni/ComponentFactoryDelegate.h | 21 +- .../react/fabric/jsi/jni/EventBeatManager.cpp | 22 +- .../react/fabric/jsi/jni/EventBeatManager.h | 31 +- .../fabric/jsi/jni/EventEmitterWrapper.cpp | 19 +- .../fabric/jsi/jni/EventEmitterWrapper.h | 16 +- .../facebook/react/fabric/jsi/jni/OnLoad.cpp | 2 +- .../jsi/jni/ReactNativeConfigHolder.cpp | 31 +- .../fabric/jsi/jni/ReactNativeConfigHolder.h | 22 +- 12 files changed, 395 insertions(+), 251 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/AsyncEventBeat.h b/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/AsyncEventBeat.h index ffffe5cae5f..8f07aa6a9fc 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/AsyncEventBeat.h +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/AsyncEventBeat.h @@ -4,56 +4,56 @@ #pragma once -#include "EventBeatManager.h" #include #include +#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 javaUIManager_; - private: - EventBeatManager *eventBeatManager_; - jsi::Runtime *runtime_; - jni::global_ref javaUIManager_; + public: + friend class EventBeatManager; - public: + AsyncEventBeat( + EventBeatManager* eventBeatManager, + jsi::Runtime* runtime, + jni::global_ref 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 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("onRequestEventBeat"); - onRequestEventBeat(javaUIManager_); - } + onRequestEventBeat(javaUIManager_); } - }; + } +}; -} +} // namespace -} -} +} // namespace react +} // namespace facebook diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/Binding.cpp b/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/Binding.cpp index 0a89c4c479e..6fa4f8c241b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/Binding.cpp +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/Binding.cpp @@ -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 #include -#include #include +#include #include #include -#include #include +#include #include #include -#include #include #include #include +#include using namespace facebook::jni; using namespace facebook::jsi; @@ -30,20 +30,22 @@ namespace react { namespace { - struct JMountItem : public JavaClass { - static constexpr auto kJavaDescriptor = "Lcom/facebook/react/fabric/mounting/mountitems/MountItem;"; - }; +struct JMountItem : public JavaClass { + 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::initHybrid( jni::alias_ref) { 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 javaUIManager, EventBeatManager* eventBeatManager, jni::alias_ref jsMessageQueueThread, ComponentFactoryDelegate* componentsRegistry, jni::alias_ref reactNativeConfig) { - Runtime* runtime = (Runtime*) jsContextNativePointer; +void Binding::installFabricUIManager( + jlong jsContextNativePointer, + jni::alias_ref javaUIManager, + EventBeatManager* eventBeatManager, + jni::alias_ref jsMessageQueueThread, + ComponentFactoryDelegate* componentsRegistry, + jni::alias_ref reactNativeConfig) { + Runtime* runtime = (Runtime*)jsContextNativePointer; javaUIManager_ = make_global(javaUIManager); - SharedContextContainer contextContainer = std::make_shared(); + SharedContextContainer contextContainer = + std::make_shared(); - auto sharedJSMessageQueueThread = std::make_shared (jsMessageQueueThread); - RuntimeExecutor runtimeExecutor = [runtime, sharedJSMessageQueueThread](std::function &&callback) { - sharedJSMessageQueueThread->runOnQueue([runtime, callback = std::move(callback)]() { - callback(*runtime); - }); - }; + auto sharedJSMessageQueueThread = + std::make_shared(jsMessageQueueThread); + RuntimeExecutor runtimeExecutor = + [runtime, sharedJSMessageQueueThread]( + std::function&& callback) { + sharedJSMessageQueueThread->runOnQueue( + [runtime, callback = std::move(callback)]() { + callback(*runtime); + }); + }; // TODO: T31905686 Create synchronous Event Beat jni::global_ref localJavaUIManager = javaUIManager_; - EventBeatFactory synchronousBeatFactory = [eventBeatManager, runtime, localJavaUIManager]() mutable { - return std::make_unique(eventBeatManager, runtime, localJavaUIManager); - }; + EventBeatFactory synchronousBeatFactory = + [eventBeatManager, runtime, localJavaUIManager]() mutable { + return std::make_unique( + eventBeatManager, runtime, localJavaUIManager); + }; - EventBeatFactory asynchronousBeatFactory = [eventBeatManager, runtime, localJavaUIManager]() mutable { - return std::make_unique(eventBeatManager, runtime, localJavaUIManager); - }; + EventBeatFactory asynchronousBeatFactory = + [eventBeatManager, runtime, localJavaUIManager]() mutable { + return std::make_unique( + eventBeatManager, runtime, localJavaUIManager); + }; // TODO: Provide non-empty impl for ReactNativeConfig. - std::shared_ptr config = std::make_shared(reactNativeConfig); + std::shared_ptr config = + std::make_shared(reactNativeConfig); contextContainer->registerInstance(config, "ReactNativeConfig"); - contextContainer->registerInstance(synchronousBeatFactory, "synchronous"); - contextContainer->registerInstance(asynchronousBeatFactory, "asynchronous"); + contextContainer->registerInstance( + synchronousBeatFactory, "synchronous"); + contextContainer->registerInstance( + asynchronousBeatFactory, "asynchronous"); contextContainer->registerInstance(javaUIManager_, "FabricUIManager"); contextContainer->registerInstance(runtimeExecutor, "runtime-executor"); - scheduler_ = std::make_shared(contextContainer, componentsRegistry->buildRegistryFunction); + scheduler_ = std::make_shared( + contextContainer, componentsRegistry->buildRegistryFunction); scheduler_->setDelegate(this); } @@ -121,16 +149,19 @@ void Binding::uninstallFabricUIManager() { javaUIManager_ = nullptr; } -inline local_ref castReadableMap(local_ref nativeMap) { +inline local_ref castReadableMap( + local_ref nativeMap) { return make_local(reinterpret_cast(nativeMap.get())); } -//TODO: this method will be removed when binding for components are code-gen -local_ref getPlatformComponentName(const ShadowView &shadowView) { +// TODO: this method will be removed when binding for components are code-gen +local_ref getPlatformComponentName(const ShadowView& shadowView) { local_ref componentName; - auto newViewProps = std::dynamic_pointer_cast(shadowView.props); + auto newViewProps = + std::dynamic_pointer_cast(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 getPlatformComponentName(const ShadowView &shadowView) { return componentName; } -local_ref createCreateMountItem(const jni::global_ref &javaUIManager, const ShadowViewMutation &mutation, const Tag rootTag) { +local_ref createCreateMountItem( + const jni::global_ref& javaUIManager, + const ShadowViewMutation& mutation, + const Tag rootTag) { static auto createJavaInstruction = - jni::findClassStatic(UIManagerJavaDescriptor) - ->getMethod(jstring,jint,jint,jboolean)>("createMountItem"); + jni::findClassStatic(UIManagerJavaDescriptor) + ->getMethod(jstring, jint, jint, jboolean)>( + "createMountItem"); auto newChildShadowView = mutation.newChildShadowView; - local_ref componentName = getPlatformComponentName(newChildShadowView); + local_ref 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 createUpdateEventEmitterMountItem(const jni::global_ref &javaUIManager, const ShadowViewMutation &mutation) { +local_ref createUpdateEventEmitterMountItem( + const jni::global_ref& javaUIManager, + const ShadowViewMutation& mutation) { if (!mutation.newChildShadowView.eventEmitter) { return nullptr; } @@ -164,37 +207,47 @@ local_ref createUpdateEventEmitterMountItem(const jni::g cEventEmitter->eventEmitter = eventEmitter; static auto updateEventEmitterInstruction = - jni::findClassStatic(UIManagerJavaDescriptor) - ->getMethod(jint, jobject)>("updateEventEmitterMountItem"); + jni::findClassStatic(UIManagerJavaDescriptor) + ->getMethod(jint, jobject)>( + "updateEventEmitterMountItem"); - return updateEventEmitterInstruction(javaUIManager, mutation.newChildShadowView.tag, javaEventEmitter.get()); + return updateEventEmitterInstruction( + javaUIManager, mutation.newChildShadowView.tag, javaEventEmitter.get()); } -local_ref createUpdatePropsMountItem(const jni::global_ref &javaUIManager, const ShadowViewMutation &mutation) { +local_ref createUpdatePropsMountItem( + const jni::global_ref& javaUIManager, + const ShadowViewMutation& mutation) { auto shadowView = mutation.newChildShadowView; - auto newViewProps = *std::dynamic_pointer_cast(shadowView.props); + auto newViewProps = + *std::dynamic_pointer_cast(shadowView.props); // TODO: move props from map to a typed object. auto newProps = shadowView.props->rawProps; - local_ref readableMap = castReadableMap(ReadableNativeMap::newObjectCxxArgs(newProps)); + local_ref readableMap = + castReadableMap(ReadableNativeMap::newObjectCxxArgs(newProps)); static auto updatePropsInstruction = - jni::findClassStatic(UIManagerJavaDescriptor) - ->getMethod(jint,ReadableMap::javaobject)>("updatePropsMountItem"); + jni::findClassStatic(UIManagerJavaDescriptor) + ->getMethod(jint, ReadableMap::javaobject)>( + "updatePropsMountItem"); - return updatePropsInstruction(javaUIManager, - mutation.newChildShadowView.tag, - readableMap.get()); + return updatePropsInstruction( + javaUIManager, mutation.newChildShadowView.tag, readableMap.get()); } -local_ref createUpdateLayoutMountItem(const jni::global_ref &javaUIManager, const ShadowViewMutation &mutation) { +local_ref createUpdateLayoutMountItem( + const jni::global_ref& 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(jint, jint, jint, jint, jint)>("updateLayoutMountItem"); + jni::findClassStatic(UIManagerJavaDescriptor) + ->getMethod(jint, jint, jint, jint, jint)>( + "updateLayoutMountItem"); auto layoutMetrics = newChildShadowView.layoutMetrics; auto pointScaleFactor = layoutMetrics.pointScaleFactor; auto frame = layoutMetrics.frame; @@ -203,24 +256,35 @@ local_ref 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 createInsertMountItem(const jni::global_ref &javaUIManager, const ShadowViewMutation &mutation) { +local_ref createInsertMountItem( + const jni::global_ref& javaUIManager, + const ShadowViewMutation& mutation) { static auto insertInstruction = - jni::findClassStatic(UIManagerJavaDescriptor) - ->getMethod(jint,jint,jint)>("insertMountItem"); + jni::findClassStatic(UIManagerJavaDescriptor) + ->getMethod(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 createUpdateLocalData(const jni::global_ref &javaUIManager, const ShadowViewMutation &mutation) { +local_ref createUpdateLocalData( + const jni::global_ref& javaUIManager, + const ShadowViewMutation& mutation) { static auto updateLocalDataInstruction = - jni::findClassStatic(UIManagerJavaDescriptor) - ->getMethod(jint, ReadableMap::javaobject)>("updateLocalDataMountItem"); + jni::findClassStatic(UIManagerJavaDescriptor) + ->getMethod(jint, ReadableMap::javaobject)>( + "updateLocalDataMountItem"); auto localData = mutation.newChildShadowView.localData; @@ -229,27 +293,44 @@ local_ref createUpdateLocalData(const jni::global_refgetDynamic(); } - local_ref readableNativeMap = ReadableNativeMap::newObjectCxxArgs(newLocalData); - return updateLocalDataInstruction(javaUIManager, mutation.newChildShadowView.tag, castReadableMap(readableNativeMap).get()); + local_ref readableNativeMap = + ReadableNativeMap::newObjectCxxArgs(newLocalData); + return updateLocalDataInstruction( + javaUIManager, + mutation.newChildShadowView.tag, + castReadableMap(readableNativeMap).get()); } -local_ref createRemoveMountItem(const jni::global_ref &javaUIManager, const ShadowViewMutation &mutation) { +local_ref createRemoveMountItem( + const jni::global_ref& javaUIManager, + const ShadowViewMutation& mutation) { static auto removeInstruction = - jni::findClassStatic(UIManagerJavaDescriptor) - ->getMethod(jint,jint,jint)>("removeMountItem"); + jni::findClassStatic(UIManagerJavaDescriptor) + ->getMethod(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 createDeleteMountItem(const jni::global_ref &javaUIManager, const ShadowViewMutation &mutation) { +local_ref createDeleteMountItem( + const jni::global_ref& javaUIManager, + const ShadowViewMutation& mutation) { static auto deleteInstruction = - jni::findClassStatic(UIManagerJavaDescriptor) - ->getMethod(jint)>("deleteMountItem"); + jni::findClassStatic(UIManagerJavaDescriptor) + ->getMethod(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> 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> mountItemsArray = JArrayClass::newArray(size); + local_ref> mountItemsArray = + JArrayClass::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(jtypeArray,jint)>("createBatchMountItem"); + jni::findClassStatic(UIManagerJavaDescriptor) + ->getMethod( + jtypeArray, jint)>( + "createBatchMountItem"); - auto batch = createMountItemsBatchContainer(javaUIManager_, mountItemsArray.get(), position); + auto batch = createMountItemsBatchContainer( + javaUIManager_, mountItemsArray.get(), position); static auto scheduleMountItems = - jni::findClassStatic(UIManagerJavaDescriptor) - ->getMethod("scheduleMountItems"); + jni::findClassStatic(UIManagerJavaDescriptor) + ->getMethod( + "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("preallocateView"); + jni::findClassStatic(UIManagerJavaDescriptor) + ->getMethod("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 diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/Binding.h b/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/Binding.h index a9be059538d..ad12aa53955 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/Binding.h +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/Binding.h @@ -4,15 +4,15 @@ #pragma once -#include "ComponentFactoryDelegate.h" -#include "EventBeatManager.h" -#include #include #include #include #include #include +#include #include +#include "ComponentFactoryDelegate.h" +#include "EventBeatManager.h" namespace facebook { namespace react { @@ -20,9 +20,9 @@ namespace react { class Instance; class Binding : public jni::HybridClass, 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 initHybrid(jni::alias_ref); - void installFabricUIManager(jlong jsContextNativePointer, jni::alias_ref javaUIManager, EventBeatManager* eventBeatManager, jni::alias_ref jsMessageQueueThread, ComponentFactoryDelegate* componentsRegistry, jni::alias_ref reactNativeConfig); + void installFabricUIManager( + jlong jsContextNativePointer, + jni::alias_ref javaUIManager, + EventBeatManager* eventBeatManager, + jni::alias_ref jsMessageQueueThread, + ComponentFactoryDelegate* componentsRegistry, + jni::alias_ref 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 diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/ComponentFactoryDelegate.cpp b/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/ComponentFactoryDelegate.cpp index f9448bb4c32..3f719cbb008 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/ComponentFactoryDelegate.cpp +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/ComponentFactoryDelegate.cpp @@ -4,24 +4,25 @@ #include "ComponentFactoryDelegate.h" #include -#include #include #include +#include using namespace facebook::jsi; namespace facebook { namespace react { -jni::local_ref ComponentFactoryDelegate::initHybrid( - jni::alias_ref) { +jni::local_ref +ComponentFactoryDelegate::initHybrid(jni::alias_ref) { return makeCxxInstance(); } void ComponentFactoryDelegate::registerNatives() { registerHybrid({ - makeNativeMethod("initHybrid", ComponentFactoryDelegate::initHybrid), + makeNativeMethod("initHybrid", ComponentFactoryDelegate::initHybrid), }); } -}} +} // namespace react +} // namespace facebook diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/ComponentFactoryDelegate.h b/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/ComponentFactoryDelegate.h index 389b94aaf22..dc6e16b43d5 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/ComponentFactoryDelegate.h +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/ComponentFactoryDelegate.h @@ -4,11 +4,11 @@ #pragma once +#include +#include #include #include #include -#include -#include #include #include @@ -19,20 +19,19 @@ namespace react { class Instance; -class ComponentFactoryDelegate : public jni::HybridClass { -public: - constexpr static const char *const kJavaDescriptor = - "Lcom/facebook/react/fabric/jsi/ComponentFactoryDelegate;"; +class ComponentFactoryDelegate + : public jni::HybridClass { + public: + constexpr static const char* const kJavaDescriptor = + "Lcom/facebook/react/fabric/jsi/ComponentFactoryDelegate;"; static void registerNatives(); ComponentRegistryFactory buildRegistryFunction; -private: - + private: static jni::local_ref initHybrid(jni::alias_ref); - }; -} -} +} // namespace react +} // namespace facebook diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/EventBeatManager.cpp b/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/EventBeatManager.cpp index b72e9c0aee9..19e79e9d843 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/EventBeatManager.cpp +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/EventBeatManager.cpp @@ -9,20 +9,24 @@ using namespace facebook::jni; namespace facebook { namespace react { -EventBeatManager::EventBeatManager(Runtime* runtime, jni::alias_ref jhybridobject) : runtime_(runtime), jhybridobject_(jhybridobject) { } +EventBeatManager::EventBeatManager( + Runtime* runtime, + jni::alias_ref jhybridobject) + : runtime_(runtime), jhybridobject_(jhybridobject) {} jni::local_ref EventBeatManager::initHybrid( - jni::alias_ref jhybridobject, jlong jsContext) { - return makeCxxInstance((Runtime *) jsContext, jhybridobject); + jni::alias_ref jhybridobject, + jlong jsContext) { + return makeCxxInstance((Runtime*)jsContext, jhybridobject); } -void EventBeatManager::registerEventBeat(EventBeat *eventBeat) const { +void EventBeatManager::registerEventBeat(EventBeat* eventBeat) const { std::lock_guard lock(mutex_); registeredEventBeats_.insert(eventBeat); } -void EventBeatManager::unregisterEventBeat(EventBeat *eventBeat) const { +void EventBeatManager::unregisterEventBeat(EventBeat* eventBeat) const { std::lock_guard 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 diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/EventBeatManager.h b/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/EventBeatManager.h index ee2d603191c..2e49a9aa383 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/EventBeatManager.h +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/EventBeatManager.h @@ -4,9 +4,9 @@ #pragma once -#include #include #include +#include #include #include @@ -18,33 +18,36 @@ namespace react { class Instance; class EventBeatManager : public jni::HybridClass { -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 jhybridobject); - -private: + EventBeatManager( + Runtime* runtime, + jni::alias_ref jhybridobject); + private: Runtime* runtime_; jni::alias_ref jhybridobject_; - mutable std::unordered_set registeredEventBeats_ {}; // Protected by `mutex_` + mutable std::unordered_set + registeredEventBeats_{}; // Protected by `mutex_` mutable std::mutex mutex_; - static jni::local_ref initHybrid(jni::alias_ref jhybridobject, jlong jsContext); - + static jni::local_ref initHybrid( + jni::alias_ref jhybridobject, + jlong jsContext); }; -} -} +} // namespace react +} // namespace facebook diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/EventEmitterWrapper.cpp b/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/EventEmitterWrapper.cpp index 81f56fc63bd..60d48341323 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/EventEmitterWrapper.cpp +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/EventEmitterWrapper.cpp @@ -10,21 +10,24 @@ using namespace facebook::jni; namespace facebook { namespace react { -jni::local_ref EventEmitterWrapper::initHybrid( - jni::alias_ref) { +jni::local_ref +EventEmitterWrapper::initHybrid(jni::alias_ref) { 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), }); } -} -} \ No newline at end of file +} // namespace react +} // namespace facebook \ No newline at end of file diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/EventEmitterWrapper.h b/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/EventEmitterWrapper.h index ec32f73db78..62db218133d 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/EventEmitterWrapper.h +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/EventEmitterWrapper.h @@ -14,21 +14,19 @@ namespace react { class Instance; class EventEmitterWrapper : public jni::HybridClass { -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 initHybrid(jni::alias_ref); - }; -} -} +} // namespace react +} // namespace facebook diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/OnLoad.cpp b/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/OnLoad.cpp index 63f4184cfd6..42c10f45f9b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/OnLoad.cpp +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/OnLoad.cpp @@ -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(); diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/ReactNativeConfigHolder.cpp b/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/ReactNativeConfigHolder.cpp index e5e61cbf820..3942bb5ffad 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/ReactNativeConfigHolder.cpp +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/ReactNativeConfigHolder.cpp @@ -11,26 +11,31 @@ using namespace facebook::react; -bool ReactNativeConfigHolder::getBool(const std::string ¶m) const { - static const auto method = facebook::jni::findClassStatic("com/facebook/react/fabric/ReactNativeConfig") - ->getMethod("getBool"); +bool ReactNativeConfigHolder::getBool(const std::string& param) const { + static const auto method = facebook::jni::findClassStatic( + "com/facebook/react/fabric/ReactNativeConfig") + ->getMethod("getBool"); return method(reactNativeConfig_, facebook::jni::make_jstring(param).get()); } -std::string ReactNativeConfigHolder::getString(const std::string ¶m) const { - static const auto method = facebook::jni::findClassStatic("com/facebook/react/fabric/ReactNativeConfig") - ->getMethod("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("getString"); + return method(reactNativeConfig_, facebook::jni::make_jstring(param).get()) + ->toString(); } -int64_t ReactNativeConfigHolder::getInt64(const std::string ¶m) const { - static const auto method = facebook::jni::findClassStatic("com/facebook/react/fabric/ReactNativeConfig") - ->getMethod("getInt64"); +int64_t ReactNativeConfigHolder::getInt64(const std::string& param) const { + static const auto method = facebook::jni::findClassStatic( + "com/facebook/react/fabric/ReactNativeConfig") + ->getMethod("getInt64"); return method(reactNativeConfig_, facebook::jni::make_jstring(param).get()); } -double ReactNativeConfigHolder::getDouble(const std::string ¶m) const { - static const auto method = facebook::jni::findClassStatic("com/facebook/react/fabric/ReactNativeConfig") - ->getMethod("getDouble"); +double ReactNativeConfigHolder::getDouble(const std::string& param) const { + static const auto method = facebook::jni::findClassStatic( + "com/facebook/react/fabric/ReactNativeConfig") + ->getMethod("getDouble"); return method(reactNativeConfig_, facebook::jni::make_jstring(param).get()); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/ReactNativeConfigHolder.h b/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/ReactNativeConfigHolder.h index 134fba31b56..b5c72caa8a9 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/ReactNativeConfigHolder.h +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jsi/jni/ReactNativeConfigHolder.h @@ -7,28 +7,30 @@ #pragma once -#include #include +#include #include #include -#include +#include 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 reactNativeConfig) : reactNativeConfig_(reactNativeConfig) {}; + public: + ReactNativeConfigHolder(jni::alias_ref reactNativeConfig) + : reactNativeConfig_(reactNativeConfig){}; - 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; + 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 reactNativeConfig_; };