From 1fc56113d2480c8604461abd368f80ab0e0fa101 Mon Sep 17 00:00:00 2001 From: Christoph Purrer Date: Mon, 6 Jan 2025 09:58:14 -0800 Subject: [PATCH] Add getSurfaceProps helper method to SurfaceManager (#48487) Summary: [Changelog] [Internal] - Add getSurfaceProps helper method to SurfaceManager When reload a reactHost we need to know which surface properties have been applied when starting the surface. This adds a utility function for that. Reviewed By: rshest Differential Revision: D67822459 --- .../react/renderer/scheduler/SurfaceManager.cpp | 16 ++++++++++++++++ .../react/renderer/scheduler/SurfaceManager.h | 13 +++++++++++++ 2 files changed, 29 insertions(+) diff --git a/packages/react-native/ReactCommon/react/renderer/scheduler/SurfaceManager.cpp b/packages/react-native/ReactCommon/react/renderer/scheduler/SurfaceManager.cpp index 5e280a68349c07..f7457841fbe9ee 100644 --- a/packages/react-native/ReactCommon/react/renderer/scheduler/SurfaceManager.cpp +++ b/packages/react-native/ReactCommon/react/renderer/scheduler/SurfaceManager.cpp @@ -78,6 +78,22 @@ void SurfaceManager::stopAllSurfaces() const noexcept { } } +std::optional SurfaceManager::getSurfaceProps( + SurfaceId surfaceId) const noexcept { + std::optional surfaceProps; + + visit(surfaceId, [&](const SurfaceHandler& surfaceHandler) { + surfaceProps = SurfaceManager::SurfaceProps{ + surfaceId, + surfaceHandler.getModuleName(), + surfaceHandler.getProps(), + surfaceHandler.getLayoutConstraints(), + surfaceHandler.getLayoutContext()}; + }); + + return surfaceProps; +} + Size SurfaceManager::measureSurface( SurfaceId surfaceId, const LayoutConstraints& layoutConstraints, diff --git a/packages/react-native/ReactCommon/react/renderer/scheduler/SurfaceManager.h b/packages/react-native/ReactCommon/react/renderer/scheduler/SurfaceManager.h index fd60f788cc0127..f04ea0e74b0019 100644 --- a/packages/react-native/ReactCommon/react/renderer/scheduler/SurfaceManager.h +++ b/packages/react-native/ReactCommon/react/renderer/scheduler/SurfaceManager.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include #include @@ -29,6 +30,15 @@ class SurfaceManager final { explicit SurfaceManager(const Scheduler& scheduler) noexcept; ~SurfaceManager() noexcept; + /* SurfaceProps contain information about running surfaces */ + struct SurfaceProps { + SurfaceId surfaceId; + std::string moduleName; + folly::dynamic props; + LayoutConstraints layoutConstraints; + LayoutContext layoutContext; + }; + #pragma mark - Surface Management void startSurface( @@ -47,6 +57,9 @@ class SurfaceManager final { void stopAllSurfaces() const noexcept; + std::optional getSurfaceProps( + SurfaceId surfaceId) const noexcept; + Size measureSurface( SurfaceId surfaceId, const LayoutConstraints& layoutConstraints,