diff --git a/packages/react-native/ReactCxxPlatform/react/renderer/scheduler/SchedulerDelegateImpl.cpp b/packages/react-native/ReactCxxPlatform/react/renderer/scheduler/SchedulerDelegateImpl.cpp new file mode 100644 index 00000000000000..f594a75c043265 --- /dev/null +++ b/packages/react-native/ReactCxxPlatform/react/renderer/scheduler/SchedulerDelegateImpl.cpp @@ -0,0 +1,56 @@ +// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary. + +#include "SchedulerDelegateImpl.h" + +namespace facebook::react { + +SchedulerDelegateImpl::SchedulerDelegateImpl( + std::shared_ptr mountingManager) noexcept + : mountingManager_(std::move(mountingManager)) {} + +void SchedulerDelegateImpl::schedulerDidFinishTransaction( + const std::shared_ptr& /*mountingCoordinator*/) { + // no-op, we will flush the transaction from schedulerShouldRenderTransactions +} + +void SchedulerDelegateImpl::schedulerShouldRenderTransactions( + const std::shared_ptr& mountingCoordinator) { + auto surfaceId = mountingCoordinator->getSurfaceId(); + if (auto transaction = mountingCoordinator->pullTransaction(); + transaction.has_value()) { + if (auto& transactionValue = transaction.value(); + !transactionValue.getMutations().empty()) { + mountingManager_->executeMount(surfaceId, std::move(transactionValue)); + } + } +} + +void SchedulerDelegateImpl::schedulerDidRequestPreliminaryViewAllocation( + const ShadowNode& shadowNode) {} + +void SchedulerDelegateImpl::schedulerDidDispatchCommand( + const ShadowView& shadowView, + const std::string& commandName, + const folly::dynamic& args) { + mountingManager_->dispatchCommand(shadowView, commandName, args); +} + +void SchedulerDelegateImpl::schedulerDidSetIsJSResponder( + const ShadowView& shadowView, + bool isJSResponder, + bool blockNativeResponder) { + mountingManager_->setIsJSResponder( + shadowView, isJSResponder, blockNativeResponder); +} + +void SchedulerDelegateImpl::schedulerDidSendAccessibilityEvent( + const ShadowView& shadowView, + const std::string& eventType) {} + +void SchedulerDelegateImpl::schedulerShouldSynchronouslyUpdateViewOnUIThread( + Tag tag, + const folly::dynamic& props) { + mountingManager_->synchronouslyUpdateViewOnUIThread(tag, props); +} + +} // namespace facebook::react diff --git a/packages/react-native/ReactCxxPlatform/react/renderer/scheduler/SchedulerDelegateImpl.h b/packages/react-native/ReactCxxPlatform/react/renderer/scheduler/SchedulerDelegateImpl.h new file mode 100644 index 00000000000000..229d21c890053d --- /dev/null +++ b/packages/react-native/ReactCxxPlatform/react/renderer/scheduler/SchedulerDelegateImpl.h @@ -0,0 +1,57 @@ +// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary. + +#pragma once + +#include +#include + +namespace facebook::react { + +class IMountingManager; + +class SchedulerDelegateImpl : public SchedulerDelegate { + public: + SchedulerDelegateImpl( + std::shared_ptr mountingManager) noexcept; + + ~SchedulerDelegateImpl() noexcept override = default; + + SchedulerDelegateImpl(SchedulerDelegateImpl&&) noexcept = default; + SchedulerDelegateImpl& operator=(SchedulerDelegateImpl&&) noexcept = default; + SchedulerDelegateImpl(const SchedulerDelegateImpl&) = delete; + SchedulerDelegateImpl& operator=(const SchedulerDelegateImpl&) = delete; + + private: + 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 schedulerDidSetIsJSResponder( + const ShadowView& shadowView, + bool isJSResponder, + bool blockNativeResponder) override; + + void schedulerDidSendAccessibilityEvent( + const ShadowView& shadowView, + const std::string& eventType) override; + + void schedulerShouldSynchronouslyUpdateViewOnUIThread( + Tag tag, + const folly::dynamic& props) override; + + std::shared_ptr mountingManager_; +}; + +}; // namespace facebook::react diff --git a/packages/react-native/ReactCxxPlatform/react/renderer/scheduler/SurfaceDelegate.h b/packages/react-native/ReactCxxPlatform/react/renderer/scheduler/SurfaceDelegate.h new file mode 100644 index 00000000000000..a62269bd11d8fe --- /dev/null +++ b/packages/react-native/ReactCxxPlatform/react/renderer/scheduler/SurfaceDelegate.h @@ -0,0 +1,41 @@ +// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary. + +#pragma once + +#include + +namespace facebook::react { +/** + * Interface for handling a surface in React Native. Each platform can have + * custom logic to show/hide. + * Inspired by + * xplat/js/react-native-github/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/SurfaceDelegate.java + */ +class SurfaceDelegate { + public: + virtual ~SurfaceDelegate() = default; + + /** + * Create the React content view that uses the appKey as the React application + * name + */ + virtual void createContentView(std::string appKey) = 0; + + /** + * Check if the content view is created and ready to be shown + */ + virtual bool isContentViewReady() = 0; + + /** Destroy the React content view to avoid memory leak */ + virtual void destroyContentView() = 0; + + /** Show the surface containing the React content view */ + virtual void show() = 0; + + /** Hide the surface containing the React content view */ + virtual void hide() = 0; + + /** Check if the surface is currently showing */ + virtual bool isShowing() = 0; +}; +} // namespace facebook::react