From da63943ba597143b2755c0cf4f1264a1e65cdd03 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Fri, 2 Oct 2026 00:56:18 -0700 Subject: [PATCH] Move ImageSource debug helpers out of primitives.h (#58791) Summary: `react/renderer/imagemanager/primitives.h` is public and re-exported by ``, but it included the private `react/renderer/debug/debugStringConvertibleUtils.h`. Under `RN_STRICT_API`, any consumer including the umbrella hit the private-header `#error`. Move the bodies of `ImageSource::getDebugProps` and the two `ImageSource::toString` overloads into a new `primitives.cpp`, which includes the private header. The header keeps only the declarations; `SharedDebugStringConvertibleList` is already provided by ``. Changelog: [Internal] Differential Revision: D122761709 --- .../renderer/imagemanager/primitives.cpp | 80 +++++++++++++++++++ .../react/renderer/imagemanager/primitives.h | 57 +------------ 2 files changed, 83 insertions(+), 54 deletions(-) create mode 100644 packages/react-native/ReactCommon/react/renderer/imagemanager/primitives.cpp diff --git a/packages/react-native/ReactCommon/react/renderer/imagemanager/primitives.cpp b/packages/react-native/ReactCommon/react/renderer/imagemanager/primitives.cpp new file mode 100644 index 000000000000..b982a45ab6b3 --- /dev/null +++ b/packages/react-native/ReactCommon/react/renderer/imagemanager/primitives.cpp @@ -0,0 +1,80 @@ +/* + * 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. + */ + +#include + +#if RN_DEBUG_STRING_CONVERTIBLE +#include +#include +#endif + +namespace facebook::react { + +#if RN_DEBUG_STRING_CONVERTIBLE +SharedDebugStringConvertibleList ImageSource::getDebugProps( + const std::string& prefix) const { + ImageSource imageSource{}; + + SharedDebugStringConvertibleList headersList; + for (const auto& header : headers) { + headersList.push_back(debugStringConvertibleItem( + prefix + "-header-" + header.first, header.second)); + } + + return headersList + + SharedDebugStringConvertibleList{ + debugStringConvertibleItem( + prefix + "-type", toString(type), toString(imageSource.type)), + debugStringConvertibleItem(prefix + "-uri", uri, imageSource.uri), + debugStringConvertibleItem( + prefix + "-bundle", bundle, imageSource.bundle), + debugStringConvertibleItem( + prefix + "-scale", scale, imageSource.scale), + debugStringConvertibleItem( + prefix + "-size", + react::toString(size), + react::toString(imageSource.size)), + debugStringConvertibleItem(prefix + "-body", body, imageSource.body), + debugStringConvertibleItem( + prefix + "-method", method, imageSource.method), + debugStringConvertibleItem( + prefix + "-cache", toString(cache), toString(imageSource.cache)), + }; +} + +std::string ImageSource::toString(const Type& typeValue) const { + switch (typeValue) { + case ImageSource::Type::Invalid: + return "invalid"; + case ImageSource::Type::Remote: + return "remote"; + case ImageSource::Type::Local: + return "local"; + default: + react_native_assert(false && "Invalid ImageSource::Type"); + return ""; + } +} + +std::string ImageSource::toString(const CacheStategy& cacheValue) const { + switch (cacheValue) { + case ImageSource::CacheStategy::Default: + return "default"; + case ImageSource::CacheStategy::Reload: + return "reload"; + case ImageSource::CacheStategy::ForceCache: + return "force-cache"; + case ImageSource::CacheStategy::OnlyIfCached: + return "only-if-cached"; + default: + react_native_assert(false && "Invalid ImageSource::CacheStategy"); + return ""; + } +} +#endif + +} // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/imagemanager/primitives.h b/packages/react-native/ReactCommon/react/renderer/imagemanager/primitives.h index 2743da4430ee..607a32874b23 100644 --- a/packages/react-native/ReactCommon/react/renderer/imagemanager/primitives.h +++ b/packages/react-native/ReactCommon/react/renderer/imagemanager/primitives.h @@ -16,7 +16,6 @@ #include #include #include -#include namespace facebook::react { @@ -96,59 +95,9 @@ class ImageSource { #endif #if RN_DEBUG_STRING_CONVERTIBLE - SharedDebugStringConvertibleList getDebugProps(const std::string &prefix) const - { - ImageSource imageSource{}; - - SharedDebugStringConvertibleList headersList; - for (const auto &header : headers) { - headersList.push_back(debugStringConvertibleItem(prefix + "-header-" + header.first, header.second)); - } - - return headersList + - SharedDebugStringConvertibleList{ - debugStringConvertibleItem(prefix + "-type", toString(type), toString(imageSource.type)), - debugStringConvertibleItem(prefix + "-uri", uri, imageSource.uri), - debugStringConvertibleItem(prefix + "-bundle", bundle, imageSource.bundle), - debugStringConvertibleItem(prefix + "-scale", scale, imageSource.scale), - debugStringConvertibleItem(prefix + "-size", react::toString(size), react::toString(imageSource.size)), - debugStringConvertibleItem(prefix + "-body", body, imageSource.body), - debugStringConvertibleItem(prefix + "-method", method, imageSource.method), - debugStringConvertibleItem(prefix + "-cache", toString(cache), toString(imageSource.cache)), - }; - } - - std::string toString(const Type &typeValue) const - { - switch (typeValue) { - case ImageSource::Type::Invalid: - return "invalid"; - case ImageSource::Type::Remote: - return "remote"; - case ImageSource::Type::Local: - return "local"; - default: - react_native_assert(false && "Invalid ImageSource::Type"); - return ""; - } - } - - std::string toString(const CacheStategy &cacheValue) const - { - switch (cacheValue) { - case ImageSource::CacheStategy::Default: - return "default"; - case ImageSource::CacheStategy::Reload: - return "reload"; - case ImageSource::CacheStategy::ForceCache: - return "force-cache"; - case ImageSource::CacheStategy::OnlyIfCached: - return "only-if-cached"; - default: - react_native_assert(false && "Invalid ImageSource::CacheStategy"); - return ""; - } - } + SharedDebugStringConvertibleList getDebugProps(const std::string &prefix) const; + std::string toString(const Type &typeValue) const; + std::string toString(const CacheStategy &cacheValue) const; #endif };