Add getSurfaceProps helper method to SurfaceManager (#48487)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48487

[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

fbshipit-source-id: 6d1f182514ed6e7ae8e31d3e1ca052c93bac2843
This commit is contained in:
Christoph Purrer
2025-01-06 21:49:49 -08:00
committed by Facebook GitHub Bot
parent 44525aaf8b
commit 65c6a0a941
2 changed files with 29 additions and 0 deletions
@@ -89,6 +89,22 @@ std::unordered_set<SurfaceId> SurfaceManager::getRunningSurfaces()
return surfaceIds;
}
std::optional<SurfaceManager::SurfaceProps> SurfaceManager::getSurfaceProps(
SurfaceId surfaceId) const noexcept {
std::optional<SurfaceManager::SurfaceProps> 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,
@@ -8,6 +8,7 @@
#pragma once
#include <mutex>
#include <optional>
#include <shared_mutex>
#include <unordered_map>
@@ -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(
@@ -46,6 +56,9 @@ class SurfaceManager final {
std::unordered_set<SurfaceId> getRunningSurfaces() const noexcept;
std::optional<SurfaceManager::SurfaceProps> getSurfaceProps(
SurfaceId surfaceId) const noexcept;
Size measureSurface(
SurfaceId surfaceId,
const LayoutConstraints& layoutConstraints,