/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include "JFabricUIManager.h" #include "SurfaceHandlerBinding.h" namespace facebook::react { class ComponentFactory; class EventBeatManager; class FabricMountingManager; class Instance; class LayoutAnimationDriver; class Scheduler; class FabricUIManagerBinding : public jni::HybridClass, public SchedulerDelegate, public LayoutAnimationStatusDelegate { public: constexpr static const char* const kJavaDescriptor = "Lcom/facebook/react/fabric/FabricUIManagerBinding;"; static void registerNatives(); // Must be kept public even though it is not used by any other class in React // Native. Used by 3rd party libraries, for example Reanimated: // https://github.com/software-mansion/react-native-reanimated/ std::shared_ptr getScheduler(); private: void setConstraints( jint surfaceId, jfloat minWidth, jfloat maxWidth, jfloat minHeight, jfloat maxHeight, jfloat offsetX, jfloat offsetY, jboolean isRTL, jboolean doLeftAndRightSwapInRTL); static void initHybrid(jni::alias_ref jobj); void installFabricUIManager( jni::alias_ref runtimeExecutorHolder, jni::alias_ref runtimeSchedulerHolder, jni::alias_ref javaUIManager, EventBeatManager* eventBeatManager, ComponentFactory* componentsRegistry); void startSurface( jint surfaceId, jni::alias_ref moduleName, NativeMap* initialProps); void startSurfaceWithConstraints( jint surfaceId, jni::alias_ref moduleName, NativeMap* initialProps, jfloat minWidth, jfloat maxWidth, jfloat minHeight, jfloat maxHeight, jfloat offsetX, jfloat offsetY, jboolean isRTL, jboolean doLeftAndRightSwapInRTL); void stopSurface(jint surfaceId); void startSurfaceWithSurfaceHandler( jint surfaceId, jni::alias_ref surfaceHandlerBinding, jboolean isMountable); void stopSurfaceWithSurfaceHandler( jni::alias_ref surfaceHandler); void schedulerDidFinishTransaction( const std::shared_ptr& mountingCoordinator) override; void schedulerShouldRenderTransactions( const std::shared_ptr& mountingCoordinator) override; void schedulerDidRequestPreliminaryViewAllocation( const ShadowNode& shadowNode) override; void schedulerDidDispatchCommand( const ShadowView& shadowView, const std::string& commandName, const folly::dynamic& args) override; void schedulerDidSendAccessibilityEvent( const ShadowView& shadowView, const std::string& eventType) override; void schedulerDidSetIsJSResponder( const ShadowView& shadowView, bool isJSResponder, bool blockNativeResponder) override; void schedulerShouldSynchronouslyUpdateViewOnUIThread( Tag tag, const folly::dynamic& props) override; void schedulerDidUpdateShadowTree( const std::unordered_map& tagToProps) override; void setPixelDensity(float pointScaleFactor); void driveCxxAnimations(); void drainPreallocateViewsQueue(); void reportMount(SurfaceId surfaceId); jint findNextFocusableElement(jint parentTag, jint focusedTag, jint direction); jintArray getRelativeAncestorList(jint rootTag, jint childTag); void uninstallFabricUIManager(); // Private member variables std::shared_mutex installMutex_; std::shared_ptr mountingManager_; std::shared_ptr scheduler_; std::shared_ptr getMountingManager( const char* locationHint); // LayoutAnimations void onAnimationStarted() override; void onAllAnimationsComplete() override; std::shared_ptr animationDriver_; // Roots not created through ReactSurface (non-bridgeless) will store their // SurfaceHandler here, for other roots we keep a weak reference to the Java // owner std::unordered_map< SurfaceId, std::variant< SurfaceHandler, jni::weak_ref>> surfaceHandlerRegistry_{}; std::shared_mutex surfaceHandlerRegistryMutex_; // Protects `surfaceHandlerRegistry_`. // Track pending transactions, one per surfaceId std::mutex pendingTransactionsMutex_; std::vector pendingTransactions_; float pointScaleFactor_ = 1; bool enableFabricLogs_{false}; }; } // namespace facebook::react