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 10e9551ecbb..286392d5590 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 @@ -12,14 +12,14 @@ #include #include #include -#include #include #include +#include #include -#include #include #include #include +#include #include using namespace facebook::jni; @@ -45,7 +45,7 @@ jni::local_ref Binding::initHybrid( return makeCxxInstance(); } -void Binding::startSurface(jint surfaceId, NativeMap* initialProps) { +void Binding::startSurface(jint surfaceId, NativeMap *initialProps) { if (scheduler_) { scheduler_->startSurface(surfaceId, "", initialProps->consume()); } @@ -54,7 +54,7 @@ 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); } @@ -91,9 +91,9 @@ void Binding::setConstraints( void Binding::installFabricUIManager( jlong jsContextNativePointer, jni::alias_ref javaUIManager, - EventBeatManager* eventBeatManager, + EventBeatManager *eventBeatManager, jni::alias_ref jsMessageQueueThread, - ComponentFactoryDelegate* componentsRegistry, + ComponentFactoryDelegate *componentsRegistry, jni::alias_ref reactNativeConfig) { javaUIManager_ = make_global(javaUIManager); @@ -103,10 +103,10 @@ void Binding::installFabricUIManager( auto sharedJSMessageQueueThread = std::make_shared(jsMessageQueueThread); - Runtime* runtime = (Runtime*)jsContextNativePointer; + Runtime *runtime = (Runtime *)jsContextNativePointer; RuntimeExecutor runtimeExecutor = [runtime, sharedJSMessageQueueThread]( - std::function&& callback) { + std::function &&callback) { sharedJSMessageQueueThread->runOnQueue( [runtime, callback = std::move(callback)]() { callback(*runtime); @@ -129,7 +129,8 @@ void Binding::installFabricUIManager( eventBeatManager, runtimeExecutor, localJavaUIManager); }; - std::shared_ptr config = std::make_shared(reactNativeConfig); + std::shared_ptr config = + std::make_shared(reactNativeConfig); contextContainer->registerInstance(config, "ReactNativeConfig"); contextContainer->registerInstance( synchronousBeatFactory, "synchronous"); @@ -155,7 +156,7 @@ inline local_ref castReadableMap( } // TODO: this method will be removed when binding for components are code-gen -local_ref getPlatformComponentName(const ShadowView& shadowView) { +local_ref getPlatformComponentName(const ShadowView &shadowView) { local_ref componentName; auto newViewProps = std::dynamic_pointer_cast(shadowView.props); @@ -170,8 +171,8 @@ local_ref getPlatformComponentName(const ShadowView& shadowView) { } local_ref createUpdateEventEmitterMountItem( - const jni::global_ref& javaUIManager, - const ShadowViewMutation& mutation) { + const jni::global_ref &javaUIManager, + const ShadowViewMutation &mutation) { if (!mutation.newChildShadowView.eventEmitter) { return nullptr; } @@ -179,7 +180,7 @@ local_ref createUpdateEventEmitterMountItem( // Do not hold a reference to javaEventEmitter from the C++ side. auto javaEventEmitter = EventEmitterWrapper::newObjectJavaArgs(); - EventEmitterWrapper* cEventEmitter = cthis(javaEventEmitter); + EventEmitterWrapper *cEventEmitter = cthis(javaEventEmitter); cEventEmitter->eventEmitter = eventEmitter; static auto updateEventEmitterInstruction = @@ -192,8 +193,8 @@ local_ref createUpdateEventEmitterMountItem( } local_ref createUpdatePropsMountItem( - const jni::global_ref& javaUIManager, - const ShadowViewMutation& mutation) { + const jni::global_ref &javaUIManager, + const ShadowViewMutation &mutation) { auto shadowView = mutation.newChildShadowView; auto newViewProps = *std::dynamic_pointer_cast(shadowView.props); @@ -213,8 +214,8 @@ local_ref createUpdatePropsMountItem( } local_ref createUpdateLayoutMountItem( - const jni::global_ref& javaUIManager, - const ShadowViewMutation& mutation) { + const jni::global_ref &javaUIManager, + const ShadowViewMutation &mutation) { auto oldChildShadowView = mutation.oldChildShadowView; auto newChildShadowView = mutation.newChildShadowView; @@ -240,8 +241,8 @@ local_ref createUpdateLayoutMountItem( } local_ref createInsertMountItem( - const jni::global_ref& javaUIManager, - const ShadowViewMutation& mutation) { + const jni::global_ref &javaUIManager, + const ShadowViewMutation &mutation) { static auto insertInstruction = jni::findClassStatic(UIManagerJavaDescriptor) ->getMethod(jint, jint, jint)>( @@ -255,8 +256,8 @@ local_ref createInsertMountItem( } local_ref createUpdateLocalData( - const jni::global_ref& javaUIManager, - const ShadowViewMutation& mutation) { + const jni::global_ref &javaUIManager, + const ShadowViewMutation &mutation) { static auto updateLocalDataInstruction = jni::findClassStatic(UIManagerJavaDescriptor) ->getMethod(jint, ReadableMap::javaobject)>( @@ -278,8 +279,8 @@ local_ref createUpdateLocalData( } local_ref createUpdateStateMountItem( - const jni::global_ref& javaUIManager, - const ShadowViewMutation& mutation) { + const jni::global_ref &javaUIManager, + const ShadowViewMutation &mutation) { static auto updateStateInstruction = jni::findClassStatic(UIManagerJavaDescriptor) ->getMethod(jint, jobject)>( @@ -293,7 +294,7 @@ local_ref createUpdateStateMountItem( local_ref javaStateWrapper = nullptr; if (state != nullptr) { javaStateWrapper = StateWrapperImpl::newObjectJavaArgs(); - StateWrapperImpl* cStateWrapper = cthis(javaStateWrapper); + StateWrapperImpl *cStateWrapper = cthis(javaStateWrapper); cStateWrapper->state_ = state; } @@ -303,10 +304,9 @@ local_ref createUpdateStateMountItem( (javaStateWrapper != nullptr ? javaStateWrapper.get() : nullptr)); } - local_ref createRemoveMountItem( - const jni::global_ref& javaUIManager, - const ShadowViewMutation& mutation) { + const jni::global_ref &javaUIManager, + const ShadowViewMutation &mutation) { static auto removeInstruction = jni::findClassStatic(UIManagerJavaDescriptor) ->getMethod(jint, jint, jint)>( @@ -320,8 +320,8 @@ local_ref createRemoveMountItem( } local_ref createDeleteMountItem( - const jni::global_ref& javaUIManager, - const ShadowViewMutation& mutation) { + const jni::global_ref &javaUIManager, + const ShadowViewMutation &mutation) { static auto deleteInstruction = jni::findClassStatic(UIManagerJavaDescriptor) ->getMethod(jint)>("deleteMountItem"); @@ -330,8 +330,8 @@ local_ref createDeleteMountItem( } local_ref createCreateMountItem( - const jni::global_ref& javaUIManager, - const ShadowViewMutation& mutation, + const jni::global_ref &javaUIManager, + const ShadowViewMutation &mutation, const Tag surfaceId) { static auto createJavaInstruction = jni::findClassStatic(UIManagerJavaDescriptor) @@ -343,7 +343,8 @@ local_ref createCreateMountItem( local_ref componentName = getPlatformComponentName(newChildShadowView); - jboolean isLayoutable = newChildShadowView.layoutMetrics != EmptyLayoutMetrics; + jboolean isLayoutable = + newChildShadowView.layoutMetrics != EmptyLayoutMetrics; return createJavaInstruction( javaUIManager, @@ -380,7 +381,7 @@ void Binding::schedulerDidFinishTransaction( std::unordered_set deletedViewTags; int position = 0; - for (const auto& mutation : mutations) { + for (const auto &mutation : mutations) { auto oldChildShadowView = mutation.oldChildShadowView; auto newChildShadowView = mutation.newChildShadowView; @@ -389,12 +390,13 @@ void Binding::schedulerDidFinishTransaction( switch (mutation.type) { case ShadowViewMutation::Create: { - if (mutation.newChildShadowView.props->revision > 1 - || deletedViewTags.find(mutation.newChildShadowView.tag) != deletedViewTags.end()) { + if (mutation.newChildShadowView.props->revision > 1 || + deletedViewTags.find(mutation.newChildShadowView.tag) != + deletedViewTags.end()) { mountItems[position++] = createCreateMountItem(javaUIManager_, mutation, surfaceId); } - break; + break; } case ShadowViewMutation::Remove: { if (!isVirtual) { @@ -448,10 +450,12 @@ void Binding::schedulerDidFinishTransaction( case ShadowViewMutation::Insert: { if (!isVirtual) { // Insert item - mountItems[position++] = createInsertMountItem(javaUIManager_, mutation); + mountItems[position++] = + createInsertMountItem(javaUIManager_, mutation); if (mutation.newChildShadowView.props->revision > 1 || - deletedViewTags.find(mutation.newChildShadowView.tag) != deletedViewTags.end()) { + deletedViewTags.find(mutation.newChildShadowView.tag) != + deletedViewTags.end()) { mountItems[position++] = createUpdatePropsMountItem(javaUIManager_, mutation); } @@ -523,12 +527,13 @@ void Binding::setPixelDensity(float pointScaleFactor) { void Binding::schedulerDidRequestPreliminaryViewAllocation( const SurfaceId surfaceId, const ShadowView &shadowView) { - bool isLayoutableShadowNode = shadowView.layoutMetrics != EmptyLayoutMetrics; static auto preallocateView = jni::findClassStatic(UIManagerJavaDescriptor) - ->getMethod("preallocateView"); + ->getMethod( + "preallocateView"); // Do not hold onto Java object from C // We DO want to hold onto C object from Java, since we don't know the @@ -536,15 +541,21 @@ void Binding::schedulerDidRequestPreliminaryViewAllocation( local_ref javaStateWrapper = nullptr; if (shadowView.state != nullptr) { javaStateWrapper = StateWrapperImpl::newObjectJavaArgs(); - StateWrapperImpl* cStateWrapper = cthis(javaStateWrapper); + StateWrapperImpl *cStateWrapper = cthis(javaStateWrapper); cStateWrapper->state_ = shadowView.state; } - local_ref props = - castReadableMap(ReadableNativeMap::newObjectCxxArgs(shadowView.props->rawProps)); + local_ref props = castReadableMap( + ReadableNativeMap::newObjectCxxArgs(shadowView.props->rawProps)); auto component = getPlatformComponentName(shadowView); preallocateView( - javaUIManager_, surfaceId, shadowView.tag, component.get(), props.get(), (javaStateWrapper != nullptr ? javaStateWrapper.get() : nullptr), isLayoutableShadowNode); + javaUIManager_, + surfaceId, + shadowView.tag, + component.get(), + props.get(), + (javaStateWrapper != nullptr ? javaStateWrapper.get() : nullptr), + isLayoutableShadowNode); } void Binding::registerNatives() { 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 d082e78f285..6486763e7ee 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 @@ -21,7 +21,7 @@ class Instance; class Binding : public jni::HybridClass, public SchedulerDelegate { public: - constexpr static const char* const kJavaDescriptor = + constexpr static const char *const kJavaDescriptor = "Lcom/facebook/react/fabric/jsi/Binding;"; static void registerNatives(); @@ -45,19 +45,19 @@ class Binding : public jni::HybridClass, public SchedulerDelegate { void installFabricUIManager( jlong jsContextNativePointer, jni::alias_ref javaUIManager, - EventBeatManager* eventBeatManager, + EventBeatManager *eventBeatManager, jni::alias_ref jsMessageQueueThread, - ComponentFactoryDelegate* componentsRegistry, + 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( - MountingCoordinator::Shared const &mountingCoordinator); + MountingCoordinator::Shared const &mountingCoordinator); void schedulerDidRequestPreliminaryViewAllocation( const SurfaceId surfaceId,