diff --git a/packages/react-native/ReactCommon/react/renderer/scheduler/SurfaceManager.cpp b/packages/react-native/ReactCommon/react/renderer/scheduler/SurfaceManager.cpp index 65e3548ccb2410..5e280a68349c07 100644 --- a/packages/react-native/ReactCommon/react/renderer/scheduler/SurfaceManager.cpp +++ b/packages/react-native/ReactCommon/react/renderer/scheduler/SurfaceManager.cpp @@ -7,6 +7,7 @@ #include "SurfaceManager.h" +#include #include namespace facebook::react { @@ -14,6 +15,12 @@ namespace facebook::react { SurfaceManager::SurfaceManager(const Scheduler& scheduler) noexcept : scheduler_(scheduler) {} +SurfaceManager::~SurfaceManager() noexcept { + LOG(WARNING) << "SurfaceManager::~SurfaceManager() was called (address: " + << this << ")."; + stopAllSurfaces(); +} + void SurfaceManager::startSurface( SurfaceId surfaceId, const std::string& moduleName, @@ -58,6 +65,19 @@ void SurfaceManager::stopSurface(SurfaceId surfaceId) const noexcept { } } +void SurfaceManager::stopAllSurfaces() const noexcept { + std::unordered_set surfaceIds; + { + std::shared_lock lock(mutex_); + for (const auto& [surfaceId, _] : registry_) { + surfaceIds.insert(surfaceId); + } + } + for (const auto& surfaceId : surfaceIds) { + stopSurface(surfaceId); + } +} + 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 db6a7499243293..fd60f788cc0127 100644 --- a/packages/react-native/ReactCommon/react/renderer/scheduler/SurfaceManager.h +++ b/packages/react-native/ReactCommon/react/renderer/scheduler/SurfaceManager.h @@ -27,6 +27,7 @@ namespace facebook::react { class SurfaceManager final { public: explicit SurfaceManager(const Scheduler& scheduler) noexcept; + ~SurfaceManager() noexcept; #pragma mark - Surface Management @@ -44,6 +45,8 @@ class SurfaceManager final { void stopSurface(SurfaceId surfaceId) const noexcept; + void stopAllSurfaces() const noexcept; + Size measureSurface( SurfaceId surfaceId, const LayoutConstraints& layoutConstraints,