mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add ImageSource debug convertions (#53042)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53042 Changelog: [Internal] Add debug convertions for ImageSource. Reviewed By: rubennorte Differential Revision: D79561513 fbshipit-source-id: f48d640d78b34a6e72d120f41f1f32ab963d1069
This commit is contained in:
committed by
Facebook GitHub Bot
parent
e9fdb23ed2
commit
dc322d91d2
@@ -40,6 +40,8 @@ describe('<Image>', () => {
|
||||
layoutMetrics-overflowInset="{top:0,right:0,bottom:0,left:0}"
|
||||
layoutMetrics-pointScaleFactor="3"
|
||||
overflow="hidden"
|
||||
source-scale="1"
|
||||
source-type="remote"
|
||||
/>,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -285,12 +285,25 @@ folly::dynamic ImageProps::getDiffProps(const Props* prevProps) const {
|
||||
|
||||
#if RN_DEBUG_STRING_CONVERTIBLE
|
||||
SharedDebugStringConvertibleList ImageProps::getDebugProps() const {
|
||||
const auto& defaultImageProps = ImageProps();
|
||||
const auto& imageProps = ImageProps();
|
||||
|
||||
auto sourcesList = SharedDebugStringConvertibleList{};
|
||||
if (sources.size() == 1) {
|
||||
sourcesList = sources[0].getDebugProps("source");
|
||||
} else if (sources.size() > 1) {
|
||||
for (const auto& source : sources) {
|
||||
std::string sourceName = "source@" + react::toString(source.scale) + "x";
|
||||
auto debugProps = source.getDebugProps(sourceName);
|
||||
sourcesList.insert(
|
||||
sourcesList.end(), debugProps.begin(), debugProps.end());
|
||||
}
|
||||
}
|
||||
|
||||
return ViewProps::getDebugProps() +
|
||||
defaultSource.getDebugProps("defaultSource") + sourcesList +
|
||||
SharedDebugStringConvertibleList{
|
||||
debugStringConvertibleItem(
|
||||
"blurRadius", blurRadius, defaultImageProps.blurRadius),
|
||||
"blurRadius", blurRadius, imageProps.blurRadius),
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -10,7 +10,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <react/renderer/core/graphicsConversions.h>
|
||||
#include <react/renderer/core/propsConversions.h>
|
||||
#include <react/renderer/debug/debugStringConvertibleUtils.h>
|
||||
#include <react/renderer/graphics/Float.h>
|
||||
#include <react/renderer/graphics/Size.h>
|
||||
|
||||
@@ -90,6 +92,66 @@ 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";
|
||||
}
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef RN_SERIALIZABLE_STATE
|
||||
|
||||
Reference in New Issue
Block a user