diff --git a/packages/react-native/React/Fabric/RCTScheduler.mm b/packages/react-native/React/Fabric/RCTScheduler.mm index 231adc5eb22b34..1e4641c7c30e6f 100644 --- a/packages/react-native/React/Fabric/RCTScheduler.mm +++ b/packages/react-native/React/Fabric/RCTScheduler.mm @@ -24,10 +24,10 @@ public: SchedulerDelegateProxy(void *scheduler) : scheduler_(scheduler) {} - void schedulerDidFinishTransaction(MountingCoordinator::Shared mountingCoordinator) override + void schedulerDidFinishTransaction(const MountingCoordinator::Shared &mountingCoordinator) override { RCTScheduler *scheduler = (__bridge RCTScheduler *)scheduler_; - [scheduler.delegate schedulerDidFinishTransaction:std::move(mountingCoordinator)]; + [scheduler.delegate schedulerDidFinishTransaction:mountingCoordinator]; } void schedulerDidRequestPreliminaryViewAllocation(SurfaceId surfaceId, const ShadowNode &shadowNode) override diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/Binding.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/Binding.java index 19caa193e40bd7..ce35686f3350c8 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/Binding.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/Binding.java @@ -40,7 +40,7 @@ public Binding() { private native void installFabricUIManager( RuntimeExecutor runtimeExecutor, RuntimeScheduler runtimeScheduler, - Object uiManager, + FabricUIManager uiManager, EventBeatManager eventBeatManager, ComponentFactory componentsRegistry, Object reactNativeConfig); diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.cpp index 36a78a671da11c..1a9743187a31cd 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.cpp @@ -8,20 +8,24 @@ #include "Binding.h" #include "AsyncEventBeat.h" +#include "ComponentFactory.h" +#include "EventBeatManager.h" #include "EventEmitterWrapper.h" +#include "FabricMountingManager.h" #include "JBackgroundExecutor.h" #include "ReactNativeConfigHolder.h" #include "StateWrapperImpl.h" +#include "SurfaceHandlerBinding.h" #include #include #include +#include #include #include #include #include -#include #include #include #include @@ -33,14 +37,6 @@ #include #include -// Included to set BaseTextProps config; can be deleted later. -#include - -#include - -using namespace facebook::jni; -using namespace facebook::jsi; - namespace facebook { namespace react { @@ -50,7 +46,7 @@ jni::local_ref Binding::initHybrid( } // Thread-safe getter -std::shared_ptr Binding::getScheduler() { +const std::shared_ptr &Binding::getScheduler() { std::shared_lock lock(installMutex_); return scheduler_; } @@ -58,7 +54,7 @@ std::shared_ptr Binding::getScheduler() { jni::local_ref Binding::getInspectorDataForInstance( jni::alias_ref eventEmitterWrapper) { - std::shared_ptr scheduler = getScheduler(); + auto &scheduler = getScheduler(); if (!scheduler) { LOG(ERROR) << "Binding::startSurface: scheduler disappeared"; return ReadableNativeMap::newObjectCxxArgs(folly::dynamic::object()); @@ -82,15 +78,14 @@ Binding::getInspectorDataForInstance( return ReadableNativeMap::newObjectCxxArgs(result); } -constexpr static auto ReactFeatureFlagsJavaDescriptor = +constexpr static auto kReactFeatureFlagsJavaDescriptor = "com/facebook/react/config/ReactFeatureFlags"; static bool getFeatureFlagValue(const char *name) { - static const auto reactFeatureFlagsJavaDescriptor = - jni::findClassStatic(ReactFeatureFlagsJavaDescriptor); - const auto field = - reactFeatureFlagsJavaDescriptor->getStaticField(name); - return reactFeatureFlagsJavaDescriptor->getStaticFieldValue(field); + static const auto reactFeatureFlagsClass = + jni::findClassStatic(kReactFeatureFlagsJavaDescriptor); + const auto field = reactFeatureFlagsClass->getStaticField(name); + return reactFeatureFlagsClass->getStaticFieldValue(field); } void Binding::setPixelDensity(float pointScaleFactor) { @@ -109,7 +104,7 @@ void Binding::startSurface( NativeMap *initialProps) { SystraceSection s("FabricUIManagerBinding::startSurface"); - std::shared_ptr scheduler = getScheduler(); + auto &scheduler = getScheduler(); if (!scheduler) { LOG(ERROR) << "Binding::startSurface: scheduler disappeared"; return; @@ -137,7 +132,7 @@ void Binding::startSurface( surfaceHandlerRegistry_.emplace(surfaceId, std::move(surfaceHandler)); } - auto mountingManager = + auto &mountingManager = verifyMountingManager("FabricUIManagerBinding::startSurface"); if (!mountingManager) { return; @@ -165,7 +160,7 @@ void Binding::startSurfaceWithConstraints( << this << ", surfaceId: " << surfaceId << ")."; } - std::shared_ptr scheduler = getScheduler(); + auto &scheduler = getScheduler(); if (!scheduler) { LOG(ERROR) << "Binding::startSurfaceWithConstraints: scheduler disappeared"; return; @@ -208,7 +203,7 @@ void Binding::startSurfaceWithConstraints( surfaceHandlerRegistry_.emplace(surfaceId, std::move(surfaceHandler)); } - auto mountingManager = verifyMountingManager( + auto &mountingManager = verifyMountingManager( "FabricUIManagerBinding::startSurfaceWithConstraints"); if (!mountingManager) { return; @@ -219,13 +214,13 @@ void Binding::startSurfaceWithConstraints( void Binding::renderTemplateToSurface(jint surfaceId, jstring uiTemplate) { SystraceSection s("FabricUIManagerBinding::renderTemplateToSurface"); - std::shared_ptr scheduler = getScheduler(); + auto &scheduler = getScheduler(); if (!scheduler) { LOG(ERROR) << "Binding::renderTemplateToSurface: scheduler disappeared"; return; } - auto env = Environment::current(); + auto env = jni::Environment::current(); const char *nativeString = env->GetStringUTFChars(uiTemplate, JNI_FALSE); scheduler->renderTemplateToSurface(surfaceId, nativeString); env->ReleaseStringUTFChars(uiTemplate, nativeString); @@ -239,7 +234,7 @@ void Binding::stopSurface(jint surfaceId) { << ", surfaceId: " << surfaceId << ")."; } - std::shared_ptr scheduler = getScheduler(); + auto &scheduler = getScheduler(); if (!scheduler) { LOG(ERROR) << "Binding::stopSurface: scheduler disappeared"; return; @@ -261,7 +256,7 @@ void Binding::stopSurface(jint surfaceId) { scheduler->unregisterSurface(surfaceHandler); } - auto mountingManager = + auto &mountingManager = verifyMountingManager("FabricUIManagerBinding::stopSurface"); if (!mountingManager) { return; @@ -278,7 +273,7 @@ void Binding::registerSurface(SurfaceHandlerBinding *surfaceHandlerBinding) { } scheduler->registerSurface(surfaceHandler); - auto mountingManager = + auto &mountingManager = verifyMountingManager("FabricUIManagerBinding::registerSurface"); if (!mountingManager) { return; @@ -295,7 +290,7 @@ void Binding::unregisterSurface(SurfaceHandlerBinding *surfaceHandlerBinding) { } scheduler->unregisterSurface(surfaceHandler); - auto mountingManager = + auto &mountingManager = verifyMountingManager("FabricUIManagerBinding::unregisterSurface"); if (!mountingManager) { return; @@ -315,7 +310,7 @@ void Binding::setConstraints( jboolean doLeftAndRightSwapInRTL) { SystraceSection s("FabricUIManagerBinding::setConstraints"); - std::shared_ptr scheduler = getScheduler(); + auto &scheduler = getScheduler(); if (!scheduler) { LOG(ERROR) << "Binding::setConstraints: scheduler disappeared"; return; @@ -358,7 +353,7 @@ void Binding::setConstraints( void Binding::installFabricUIManager( jni::alias_ref runtimeExecutorHolder, jni::alias_ref runtimeSchedulerHolder, - jni::alias_ref javaUIManager, + jni::alias_ref javaUIManager, EventBeatManager *eventBeatManager, ComponentFactory *componentsRegistry, jni::alias_ref reactNativeConfig) { @@ -375,8 +370,6 @@ void Binding::installFabricUIManager( << this << ")."; } - // Use std::lock and std::adopt_lock to prevent deadlocks by locking mutexes - // at the same time std::unique_lock lock(installMutex_); auto globalJavaUiManager = make_global(javaUIManager); @@ -431,13 +424,10 @@ void Binding::installFabricUIManager( CoreFeatures::cacheLastTextMeasurement = getFeatureFlagValue("enableTextMeasureCachePerShadowNode"); - - // Props setter pattern feature CoreFeatures::enablePropIteratorSetter = getFeatureFlagValue("enableCppPropsIteratorSetter"); - - // NativeState experiment CoreFeatures::useNativeState = getFeatureFlagValue("useNativeState"); + CoreFeatures::enableMapBuffer = getFeatureFlagValue("useMapBufferProps"); // RemoveDelete mega-op ShadowViewMutation::PlatformSupportsRemoveDeleteTreeInstruction = @@ -480,24 +470,23 @@ void Binding::uninstallFabricUIManager() { reactNativeConfig_ = nullptr; } -std::shared_ptr Binding::verifyMountingManager( - std::string const &hint) { +const std::shared_ptr &Binding::verifyMountingManager( + const char *locationHint) { std::shared_lock lock(installMutex_); if (!mountingManager_) { - LOG(ERROR) << hint << " mounting manager disappeared."; + LOG(ERROR) << locationHint << " mounting manager disappeared."; } return mountingManager_; } void Binding::schedulerDidFinishTransaction( - MountingCoordinator::Shared mountingCoordinator) { - auto mountingManager = + const MountingCoordinator::Shared &mountingCoordinator) { + auto &mountingManager = verifyMountingManager("Binding::schedulerDidFinishTransaction"); if (!mountingManager) { return; } - - mountingManager->executeMount(std::move(mountingCoordinator)); + mountingManager->executeMount(mountingCoordinator); } void Binding::schedulerDidRequestPreliminaryViewAllocation( @@ -515,11 +504,10 @@ void Binding::preallocateView( ShadowNode const &shadowNode) { auto name = std::string(shadowNode.getComponentName()); auto shadowView = ShadowView(shadowNode); - auto mountingManager = verifyMountingManager("Binding::preallocateView"); + auto &mountingManager = verifyMountingManager("Binding::preallocateView"); if (!mountingManager) { return; } - mountingManager->preallocateShadowView(surfaceId, shadowView); } @@ -527,24 +515,22 @@ void Binding::schedulerDidDispatchCommand( const ShadowView &shadowView, std::string const &commandName, folly::dynamic const &args) { - auto mountingManager = + auto &mountingManager = verifyMountingManager("Binding::schedulerDidDispatchCommand"); if (!mountingManager) { return; } - mountingManager->dispatchCommand(shadowView, commandName, args); } void Binding::schedulerDidSendAccessibilityEvent( const ShadowView &shadowView, std::string const &eventType) { - auto mountingManager = + auto &mountingManager = verifyMountingManager("Binding::schedulerDidSendAccessibilityEvent"); if (!mountingManager) { return; } - mountingManager->sendAccessibilityEvent(shadowView, eventType); } @@ -552,31 +538,28 @@ void Binding::schedulerDidSetIsJSResponder( ShadowView const &shadowView, bool isJSResponder, bool blockNativeResponder) { - auto mountingManager = + auto &mountingManager = verifyMountingManager("Binding::schedulerDidSetIsJSResponder"); if (!mountingManager) { return; } - mountingManager->setIsJSResponder( shadowView, isJSResponder, blockNativeResponder); } void Binding::onAnimationStarted() { - auto mountingManager = verifyMountingManager("Binding::onAnimationStarted"); + auto &mountingManager = verifyMountingManager("Binding::onAnimationStarted"); if (!mountingManager) { return; } - mountingManager->onAnimationStarted(); } void Binding::onAllAnimationsComplete() { - auto mountingManager = verifyMountingManager("Binding::onAnimationComplete"); + auto &mountingManager = verifyMountingManager("Binding::onAnimationComplete"); if (!mountingManager) { return; } - mountingManager->onAllAnimationsComplete(); } diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.h b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.h index 318fa1e27c5a08..0c18855fb9be19 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.h +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.h @@ -7,8 +7,6 @@ #pragma once -#include "FabricMountingManager.h" - #include #include @@ -16,20 +14,25 @@ #include #include #include -#include -#include #include +#include #include +#include -#include "ComponentFactory.h" -#include "EventBeatManager.h" #include "EventEmitterWrapper.h" -#include "SurfaceHandlerBinding.h" +#include "JFabricUIManager.h" namespace facebook { namespace react { +class ComponentFactory; +class EventBeatManager; +class FabricMountingManager; class Instance; +class LayoutAnimationDriver; +class ReactNativeConfig; +class Scheduler; +class SurfaceHandlerBinding; class Binding : public jni::HybridClass, public SchedulerDelegate, @@ -40,7 +43,7 @@ class Binding : public jni::HybridClass, static void registerNatives(); - std::shared_ptr getScheduler(); + const std::shared_ptr &getScheduler(); private: void setConstraints( @@ -62,7 +65,7 @@ class Binding : public jni::HybridClass, void installFabricUIManager( jni::alias_ref runtimeExecutorHolder, jni::alias_ref runtimeSchedulerHolder, - jni::alias_ref javaUIManager, + jni::alias_ref javaUIManager, EventBeatManager *eventBeatManager, ComponentFactory *componentsRegistry, jni::alias_ref reactNativeConfig); @@ -94,7 +97,7 @@ class Binding : public jni::HybridClass, void unregisterSurface(SurfaceHandlerBinding *surfaceHandler); void schedulerDidFinishTransaction( - MountingCoordinator::Shared mountingCoordinator) override; + const MountingCoordinator::Shared &mountingCoordinator) override; void schedulerDidRequestPreliminaryViewAllocation( const SurfaceId surfaceId, @@ -127,8 +130,8 @@ class Binding : public jni::HybridClass, std::shared_ptr mountingManager_; std::shared_ptr scheduler_; - std::shared_ptr verifyMountingManager( - std::string const &locationHint); + const std::shared_ptr &verifyMountingManager( + const char *locationHint); // LayoutAnimations void onAnimationStarted() override; diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp index 54845eb97a89cd..5b6d19b737f0e0 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp @@ -6,7 +6,9 @@ */ #include "FabricMountingManager.h" + #include "EventEmitterWrapper.h" +#include "FabricMountItem.h" #include "StateWrapperImpl.h" #include @@ -14,6 +16,7 @@ #include #include #include +#include #include #include @@ -23,27 +26,25 @@ #include #include -using namespace facebook::jni; - namespace facebook { namespace react { +constexpr static auto kReactFeatureFlagsJavaDescriptor = + "com/facebook/react/config/ReactFeatureFlags"; + static bool getFeatureFlagValue(const char *name) { - static const auto reactFeatureFlagsJavaDescriptor = jni::findClassStatic( - FabricMountingManager::ReactFeatureFlagsJavaDescriptor); - const auto field = - reactFeatureFlagsJavaDescriptor->getStaticField(name); - return reactFeatureFlagsJavaDescriptor->getStaticFieldValue(field); + static const auto reactFeatureFlagsClass = + jni::findClassStatic(kReactFeatureFlagsJavaDescriptor); + const auto field = reactFeatureFlagsClass->getStaticField(name); + return reactFeatureFlagsClass->getStaticFieldValue(field); } FabricMountingManager::FabricMountingManager( std::shared_ptr &config, - global_ref &javaUIManager) + jni::global_ref &javaUIManager) : javaUIManager_(javaUIManager), reduceDeleteCreateMutation_( - getFeatureFlagValue("reduceDeleteCreateMutation")) { - CoreFeatures::enableMapBuffer = getFeatureFlagValue("useMapBufferProps"); -} + getFeatureFlagValue("reduceDeleteCreateMutation")) {} void FabricMountingManager::onSurfaceStart(SurfaceId surfaceId) { std::lock_guard lock(allocatedViewsMutex_); @@ -203,27 +204,21 @@ static inline void writeIntBufferTypePreamble( } } -inline local_ref castReadableArray( - local_ref const &nativeArray) { - return make_local( - reinterpret_cast(nativeArray.get())); -} - // TODO: this method will be removed when binding for components are code-gen -local_ref getPlatformComponentName(ShadowView const &shadowView) { +jni::local_ref getPlatformComponentName(ShadowView const &shadowView) { static std::string scrollViewComponentName = std::string("ScrollView"); - local_ref componentName; + jni::local_ref componentName; if (scrollViewComponentName == shadowView.componentName) { auto newViewProps = std::static_pointer_cast(shadowView.props); if (newViewProps->getProbablyMoreHorizontalThanVertical_DEPRECATED()) { - componentName = make_jstring("AndroidHorizontalScrollView"); + componentName = jni::make_jstring("AndroidHorizontalScrollView"); return componentName; } } - componentName = make_jstring(shadowView.componentName); + componentName = jni::make_jstring(shadowView.componentName); return componentName; } @@ -243,7 +238,7 @@ static inline float scale(Float value, Float pointScaleFactor) { return result; } -local_ref FabricMountingManager::getProps( +jni::local_ref FabricMountingManager::getProps( ShadowView const &oldShadowView, ShadowView const &newShadowView) { if (CoreFeatures::enableMapBuffer && @@ -263,7 +258,7 @@ local_ref FabricMountingManager::getProps( } void FabricMountingManager::executeMount( - MountingCoordinator::Shared mountingCoordinator) { + const MountingCoordinator::Shared &mountingCoordinator) { std::lock_guard lock(commitMutex_); SystraceSection s( @@ -276,7 +271,7 @@ void FabricMountingManager::executeMount( return; } - auto env = Environment::current(); + auto env = jni::Environment::current(); auto telemetry = mountingTransaction->getTelemetry(); auto surfaceId = mountingTransaction->getSurfaceId(); @@ -515,12 +510,12 @@ void FabricMountingManager::executeMount( cppViewMutations); static auto createMountItemsIntBufferBatchContainer = - jni::findClassStatic(UIManagerJavaDescriptor) - ->getMethod( - jint, jintArray, jtypeArray, jint)>( + JFabricUIManager::javaClassStatic() + ->getMethod( + jint, jintArray, jni::jtypeArray, jint)>( "createIntBufferBatchMountItem"); - static auto scheduleMountItem = jni::findClassStatic(UIManagerJavaDescriptor) + static auto scheduleMountItem = JFabricUIManager::javaClassStatic() ->getMethodNewIntArray(batchMountItemIntsSize); - local_ref> objBufferArray = - JArrayClass::newArray(batchMountItemObjectsSize); + auto objBufferArray = + jni::JArrayClass::newArray(batchMountItemObjectsSize); // Fill in arrays int intBufferPosition = 0; @@ -585,19 +580,19 @@ void FabricMountingManager::executeMount( // TODO: multi-create, multi-insert, etc if (mountItemType == CppMountItem::Type::Create) { - local_ref componentName = + auto componentName = getPlatformComponentName(mountItem.newChildShadowView); int isLayoutable = mountItem.newChildShadowView.layoutMetrics != EmptyLayoutMetrics ? 1 : 0; - local_ref props = + jni::local_ref props = getProps(mountItem.oldChildShadowView, mountItem.newChildShadowView); // Do not hold onto Java object from C // We DO want to hold onto C object from Java, since we don't know the // lifetime of the Java object - local_ref javaStateWrapper = nullptr; + jni::local_ref javaStateWrapper = nullptr; if (mountItem.newChildShadowView.state != nullptr) { javaStateWrapper = StateWrapperImpl::newObjectJavaArgs(); StateWrapperImpl *cStateWrapper = cthis(javaStateWrapper); @@ -675,7 +670,7 @@ void FabricMountingManager::executeMount( // Do not hold onto Java object from C // We DO want to hold onto C object from Java, since we don't know the // lifetime of the Java object - local_ref javaStateWrapper = nullptr; + jni::local_ref javaStateWrapper = nullptr; if (state != nullptr) { javaStateWrapper = StateWrapperImpl::newObjectJavaArgs(); StateWrapperImpl *cStateWrapper = cthis(javaStateWrapper); @@ -864,7 +859,7 @@ void FabricMountingManager::preallocateShadowView( bool isLayoutableShadowNode = shadowView.layoutMetrics != EmptyLayoutMetrics; static auto preallocateView = - jni::findClassStatic(UIManagerJavaDescriptor) + JFabricUIManager::javaClassStatic() ->getMethod( "preallocateView"); @@ -872,7 +867,7 @@ void FabricMountingManager::preallocateShadowView( // Do not hold onto Java object from C // We DO want to hold onto C object from Java, since we don't know the // lifetime of the Java object - local_ref javaStateWrapper = nullptr; + jni::local_ref javaStateWrapper = nullptr; if (shadowView.state != nullptr) { javaStateWrapper = StateWrapperImpl::newObjectJavaArgs(); StateWrapperImpl *cStateWrapper = cthis(javaStateWrapper); @@ -880,9 +875,9 @@ void FabricMountingManager::preallocateShadowView( } // Do not hold a reference to javaEventEmitter from the C++ side. - local_ref javaEventEmitter = nullptr; + jni::local_ref javaEventEmitter = nullptr; - local_ref props = getProps({}, shadowView); + jni::local_ref props = getProps({}, shadowView); auto component = getPlatformComponentName(shadowView); @@ -902,15 +897,12 @@ void FabricMountingManager::dispatchCommand( std::string const &commandName, folly::dynamic const &args) { static auto dispatchCommand = - jni::findClassStatic(UIManagerJavaDescriptor) + JFabricUIManager::javaClassStatic() ->getMethod( "dispatchCommand"); - - local_ref command = make_jstring(commandName); - - local_ref argsArray = - castReadableArray(ReadableNativeArray::newObjectCxxArgs(args)); - + auto command = jni::make_jstring(commandName); + auto argsArray = jni::adopt_local(reinterpret_cast( + ReadableNativeArray::newObjectCxxArgs(args).release())); dispatchCommand( javaUIManager_, shadowView.surfaceId, @@ -922,13 +914,11 @@ void FabricMountingManager::dispatchCommand( void FabricMountingManager::sendAccessibilityEvent( ShadowView const &shadowView, std::string const &eventType) { - local_ref eventTypeStr = make_jstring(eventType); - static auto sendAccessibilityEventFromJS = - jni::findClassStatic(UIManagerJavaDescriptor) - ->getMethod( - "sendAccessibilityEventFromJS"); + JFabricUIManager::javaClassStatic()->getMethod( + "sendAccessibilityEventFromJS"); + auto eventTypeStr = jni::make_jstring(eventType); sendAccessibilityEventFromJS( javaUIManager_, shadowView.surfaceId, shadowView.tag, eventTypeStr.get()); } @@ -938,11 +928,12 @@ void FabricMountingManager::setIsJSResponder( bool isJSResponder, bool blockNativeResponder) { static auto setJSResponder = - jni::findClassStatic(UIManagerJavaDescriptor) + JFabricUIManager::javaClassStatic() ->getMethod("setJSResponder"); - static auto clearJSResponder = jni::findClassStatic(UIManagerJavaDescriptor) - ->getMethod("clearJSResponder"); + static auto clearJSResponder = + JFabricUIManager::javaClassStatic()->getMethod( + "clearJSResponder"); if (isJSResponder) { setJSResponder( @@ -962,16 +953,16 @@ void FabricMountingManager::setIsJSResponder( void FabricMountingManager::onAnimationStarted() { static auto layoutAnimationsStartedJNI = - jni::findClassStatic(UIManagerJavaDescriptor) - ->getMethod("onAnimationStarted"); + JFabricUIManager::javaClassStatic()->getMethod( + "onAnimationStarted"); layoutAnimationsStartedJNI(javaUIManager_); } void FabricMountingManager::onAllAnimationsComplete() { static auto allAnimationsCompleteJNI = - jni::findClassStatic(UIManagerJavaDescriptor) - ->getMethod("onAllAnimationsComplete"); + JFabricUIManager::javaClassStatic()->getMethod( + "onAllAnimationsComplete"); allAnimationsCompleteJNI(javaUIManager_); } diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.h b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.h index cc970489a39421..01248be957cbd1 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.h +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.h @@ -7,33 +7,25 @@ #pragma once -#include "FabricMountItem.h" - -#include -#include -#include -#include -#include -#include +#include +#include #include - -#include +#include +#include +#include namespace facebook { namespace react { +class ReactNativeConfig; +struct ShadowView; + class FabricMountingManager final { public: - constexpr static auto UIManagerJavaDescriptor = - "com/facebook/react/fabric/FabricUIManager"; - - constexpr static auto ReactFeatureFlagsJavaDescriptor = - "com/facebook/react/config/ReactFeatureFlags"; - FabricMountingManager( std::shared_ptr &config, - jni::global_ref &javaUIManager); + jni::global_ref &javaUIManager); void onSurfaceStart(SurfaceId surfaceId); @@ -41,7 +33,7 @@ class FabricMountingManager final { void preallocateShadowView(SurfaceId surfaceId, ShadowView const &shadowView); - void executeMount(MountingCoordinator::Shared mountingCoordinator); + void executeMount(const MountingCoordinator::Shared &mountingCoordinator); void dispatchCommand( ShadowView const &shadowView, @@ -62,7 +54,7 @@ class FabricMountingManager final { void onAllAnimationsComplete(); private: - jni::global_ref javaUIManager_; + jni::global_ref javaUIManager_; std::recursive_mutex commitMutex_; diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.cpp index 595cccd6c7adc6..24c9392ee9fdfd 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.cpp @@ -7,6 +7,8 @@ #include "JFabricUIManager.h" +#include "Binding.h" + namespace facebook::react { Binding *JFabricUIManager::getBinding() { diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.h b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.h index d1c184694dee01..f801b21ebaf385 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.h +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.h @@ -9,10 +9,10 @@ #include -#include "Binding.h" - namespace facebook::react { +class Binding; + class JFabricUIManager : public jni::JavaClass { public: static constexpr auto kJavaDescriptor = diff --git a/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp b/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp index 25f31ab4c7dd8f..90d558985b9567 100644 --- a/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp +++ b/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp @@ -320,15 +320,13 @@ void Scheduler::uiManagerDidFinishTransaction( [delegate = delegate_, mountingCoordinator = std::move(mountingCoordinator)](jsi::Runtime &) { - delegate->schedulerDidFinishTransaction( - std::move(mountingCoordinator)); + delegate->schedulerDidFinishTransaction(mountingCoordinator); }); } else { - delegate_->schedulerDidFinishTransaction( - std::move(mountingCoordinator)); + delegate_->schedulerDidFinishTransaction(mountingCoordinator); } } else { - delegate_->schedulerDidFinishTransaction(std::move(mountingCoordinator)); + delegate_->schedulerDidFinishTransaction(mountingCoordinator); } } } diff --git a/packages/react-native/ReactCommon/react/renderer/scheduler/SchedulerDelegate.h b/packages/react-native/ReactCommon/react/renderer/scheduler/SchedulerDelegate.h index c0fca4a012f38e..a5159f1eeefda6 100644 --- a/packages/react-native/ReactCommon/react/renderer/scheduler/SchedulerDelegate.h +++ b/packages/react-native/ReactCommon/react/renderer/scheduler/SchedulerDelegate.h @@ -26,7 +26,7 @@ class SchedulerDelegate { * to construct a new one. */ virtual void schedulerDidFinishTransaction( - MountingCoordinator::Shared mountingCoordinator) = 0; + const MountingCoordinator::Shared &mountingCoordinator) = 0; /* * Called right after a new ShadowNode was created.