Skip to content

Commit e47e025

Browse files
j-piaseckifacebook-github-bot
authored andcommitted
Move ImageSource debug helpers out of primitives.h
Summary: `react/renderer/imagemanager/primitives.h` is public and re-exported by `<React/ImageManager.h>`, 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 `<React/RendererDebug.h>`. Changelog: [Internal] Differential Revision: D122761709
1 parent 5954b12 commit e47e025

2 files changed

Lines changed: 83 additions & 54 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include <react/renderer/imagemanager/primitives.h>
9+
10+
#if RN_DEBUG_STRING_CONVERTIBLE
11+
#include <react/debug/react_native_assert.h>
12+
#include <react/renderer/debug/debugStringConvertibleUtils.h>
13+
#endif
14+
15+
namespace facebook::react {
16+
17+
#if RN_DEBUG_STRING_CONVERTIBLE
18+
SharedDebugStringConvertibleList ImageSource::getDebugProps(
19+
const std::string& prefix) const {
20+
ImageSource imageSource{};
21+
22+
SharedDebugStringConvertibleList headersList;
23+
for (const auto& header : headers) {
24+
headersList.push_back(debugStringConvertibleItem(
25+
prefix + "-header-" + header.first, header.second));
26+
}
27+
28+
return headersList +
29+
SharedDebugStringConvertibleList{
30+
debugStringConvertibleItem(
31+
prefix + "-type", toString(type), toString(imageSource.type)),
32+
debugStringConvertibleItem(prefix + "-uri", uri, imageSource.uri),
33+
debugStringConvertibleItem(
34+
prefix + "-bundle", bundle, imageSource.bundle),
35+
debugStringConvertibleItem(
36+
prefix + "-scale", scale, imageSource.scale),
37+
debugStringConvertibleItem(
38+
prefix + "-size",
39+
react::toString(size),
40+
react::toString(imageSource.size)),
41+
debugStringConvertibleItem(prefix + "-body", body, imageSource.body),
42+
debugStringConvertibleItem(
43+
prefix + "-method", method, imageSource.method),
44+
debugStringConvertibleItem(
45+
prefix + "-cache", toString(cache), toString(imageSource.cache)),
46+
};
47+
}
48+
49+
std::string ImageSource::toString(const Type& typeValue) const {
50+
switch (typeValue) {
51+
case ImageSource::Type::Invalid:
52+
return "invalid";
53+
case ImageSource::Type::Remote:
54+
return "remote";
55+
case ImageSource::Type::Local:
56+
return "local";
57+
default:
58+
react_native_assert(false && "Invalid ImageSource::Type");
59+
return "";
60+
}
61+
}
62+
63+
std::string ImageSource::toString(const CacheStategy& cacheValue) const {
64+
switch (cacheValue) {
65+
case ImageSource::CacheStategy::Default:
66+
return "default";
67+
case ImageSource::CacheStategy::Reload:
68+
return "reload";
69+
case ImageSource::CacheStategy::ForceCache:
70+
return "force-cache";
71+
case ImageSource::CacheStategy::OnlyIfCached:
72+
return "only-if-cached";
73+
default:
74+
react_native_assert(false && "Invalid ImageSource::CacheStategy");
75+
return "";
76+
}
77+
}
78+
#endif
79+
80+
} // namespace facebook::react

‎packages/react-native/ReactCommon/react/renderer/imagemanager/primitives.h‎

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <React/Graphics.h>
1717
#include <React/RendererCore.h>
1818
#include <React/RendererDebug.h>
19-
#include <react/renderer/debug/debugStringConvertibleUtils.h>
2019

2120
namespace facebook::react {
2221

@@ -96,59 +95,9 @@ class ImageSource {
9695
#endif
9796

9897
#if RN_DEBUG_STRING_CONVERTIBLE
99-
SharedDebugStringConvertibleList getDebugProps(const std::string &prefix) const
100-
{
101-
ImageSource imageSource{};
102-
103-
SharedDebugStringConvertibleList headersList;
104-
for (const auto &header : headers) {
105-
headersList.push_back(debugStringConvertibleItem(prefix + "-header-" + header.first, header.second));
106-
}
107-
108-
return headersList +
109-
SharedDebugStringConvertibleList{
110-
debugStringConvertibleItem(prefix + "-type", toString(type), toString(imageSource.type)),
111-
debugStringConvertibleItem(prefix + "-uri", uri, imageSource.uri),
112-
debugStringConvertibleItem(prefix + "-bundle", bundle, imageSource.bundle),
113-
debugStringConvertibleItem(prefix + "-scale", scale, imageSource.scale),
114-
debugStringConvertibleItem(prefix + "-size", react::toString(size), react::toString(imageSource.size)),
115-
debugStringConvertibleItem(prefix + "-body", body, imageSource.body),
116-
debugStringConvertibleItem(prefix + "-method", method, imageSource.method),
117-
debugStringConvertibleItem(prefix + "-cache", toString(cache), toString(imageSource.cache)),
118-
};
119-
}
120-
121-
std::string toString(const Type &typeValue) const
122-
{
123-
switch (typeValue) {
124-
case ImageSource::Type::Invalid:
125-
return "invalid";
126-
case ImageSource::Type::Remote:
127-
return "remote";
128-
case ImageSource::Type::Local:
129-
return "local";
130-
default:
131-
react_native_assert(false && "Invalid ImageSource::Type");
132-
return "";
133-
}
134-
}
135-
136-
std::string toString(const CacheStategy &cacheValue) const
137-
{
138-
switch (cacheValue) {
139-
case ImageSource::CacheStategy::Default:
140-
return "default";
141-
case ImageSource::CacheStategy::Reload:
142-
return "reload";
143-
case ImageSource::CacheStategy::ForceCache:
144-
return "force-cache";
145-
case ImageSource::CacheStategy::OnlyIfCached:
146-
return "only-if-cached";
147-
default:
148-
react_native_assert(false && "Invalid ImageSource::CacheStategy");
149-
return "";
150-
}
151-
}
98+
SharedDebugStringConvertibleList getDebugProps(const std::string &prefix) const;
99+
std::string toString(const Type &typeValue) const;
100+
std::string toString(const CacheStategy &cacheValue) const;
152101
#endif
153102
};
154103

0 commit comments

Comments
 (0)