Add toDynamic conversion function for ImageSource (#52237)

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

For array props conversion following later in this stack, each type should have a toDynamic conversion available that can be called upon to convert all supported types to a `folly::dynamic` result.

This diff adds the toDynamic conversion function for `ImageSource`

 Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D77234063

fbshipit-source-id: 392cbaf172595936f7f66faa824900dadd58bdcf
This commit is contained in:
Nick Lefever
2025-06-25 04:33:12 -07:00
committed by Facebook GitHub Bot
parent dca83bc158
commit da0938edfd
6 changed files with 16 additions and 10 deletions
@@ -532,7 +532,7 @@ folly::dynamic ImagePropNativeComponentViewProps::getDiffProps(
folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps);
if (thumbImage != oldProps->thumbImage) {
result[\\"thumbImage\\"] = thumbImage.toDynamic();
result[\\"thumbImage\\"] = toDynamic(thumbImage);
}
return result;
}
@@ -740,7 +740,7 @@ folly::dynamic MultiNativePropNativeComponentViewProps::getDiffProps(
folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps);
if (thumbImage != oldProps->thumbImage) {
result[\\"thumbImage\\"] = thumbImage.toDynamic();
result[\\"thumbImage\\"] = toDynamic(thumbImage);
}
if (color != oldProps->color) {
@@ -532,7 +532,7 @@ folly::dynamic ImagePropNativeComponentViewProps::getDiffProps(
folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps);
if (thumbImage != oldProps->thumbImage) {
result[\\"thumbImage\\"] = thumbImage.toDynamic();
result[\\"thumbImage\\"] = toDynamic(thumbImage);
}
return result;
}
@@ -740,7 +740,7 @@ folly::dynamic MultiNativePropNativeComponentViewProps::getDiffProps(
folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps);
if (thumbImage != oldProps->thumbImage) {
result[\\"thumbImage\\"] = thumbImage.toDynamic();
result[\\"thumbImage\\"] = toDynamic(thumbImage);
}
if (color != oldProps->color) {
@@ -105,7 +105,7 @@ function generatePropsDiffString(
case 'ImageSourcePrimitive':
return `
if (${prop.name} != oldProps->${prop.name}) {
result["${prop.name}"] = ${prop.name}.toDynamic();
result["${prop.name}"] = toDynamic(${prop.name});
}`;
case 'ImageRequestPrimitive':
// Shouldn't be used in props
@@ -852,7 +852,7 @@ folly::dynamic ImagePropNativeComponentProps::getDiffProps(
folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps);
if (thumbImage != oldProps->thumbImage) {
result[\\"thumbImage\\"] = thumbImage.toDynamic();
result[\\"thumbImage\\"] = toDynamic(thumbImage);
}
return result;
}
@@ -1152,7 +1152,7 @@ folly::dynamic ImageColorPropNativeComponentProps::getDiffProps(
folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps);
if (thumbImage != oldProps->thumbImage) {
result[\\"thumbImage\\"] = thumbImage.toDynamic();
result[\\"thumbImage\\"] = toDynamic(thumbImage);
}
if (color != oldProps->color) {
@@ -201,17 +201,17 @@ folly::dynamic ImageProps::getDiffProps(const Props* prevProps) const {
if (sources != oldProps->sources) {
auto sourcesArray = folly::dynamic::array();
for (const auto& source : sources) {
sourcesArray.push_back(source.toDynamic());
sourcesArray.push_back(toDynamic(source));
}
result["source"] = sourcesArray;
}
if (defaultSource != oldProps->defaultSource) {
result["defaultSource"] = defaultSource.toDynamic();
result["defaultSource"] = toDynamic(defaultSource);
}
if (loadingIndicatorSource != oldProps->loadingIndicatorSource) {
result["loadingIndicatorSource"] = loadingIndicatorSource.toDynamic();
result["loadingIndicatorSource"] = toDynamic(loadingIndicatorSource);
}
if (resizeMode != oldProps->resizeMode) {
@@ -92,6 +92,12 @@ class ImageSource {
#endif
};
#ifdef RN_SERIALIZABLE_STATE
inline folly::dynamic toDynamic(const ImageSource& imageSource) {
return imageSource.toDynamic();
}
#endif
using ImageSources = std::vector<ImageSource>;
enum class ImageResizeMode {