Fix ImageSource require (#50963)

Summary:
In react-native-svg, I found that the `Image` component stopped working starting with `react-native@0.79`. After some debugging, I traced the issue to the migration of `Libraries/Image` to the new export syntax (see https://github.com/facebook/react-native/commit/8783196ee540f8f78ce60ad20800338cc7645194). To fix this, I updated the import to match other requires, similar to https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js#L84.

[GENERAL] [FIXED] - Fix codegen ImageSource require

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

Test Plan:
`validAttributes` process should be a function instead of object with a default property.

Before:
<img width="1041" alt="image" src="https://github.com/user-attachments/assets/9fbc9e9f-6c45-4b0b-adb8-2eb911676fe1" />

After:
<img width="1005" alt="image" src="https://github.com/user-attachments/assets/ee594103-90da-4917-8252-72f4ecfc28e1" />

Reviewed By: Abbondanzo

Differential Revision: D73778127

Pulled By: huntie

fbshipit-source-id: ae80c770e8e578794ae1356751f170ff955e1f5a
This commit is contained in:
Jakub Grzywacz authored and Fabrizio Cucci committed 2025-05-01 15:05:09 +01:00
1 parent a99773d8d7
commit a13be817cc
3 files changed
+5 -5

No files matched your search

@@ -367,7 +367,7 @@ export const __INTERNAL_VIEW_CONFIG = {
uiViewClassName: \\"ImagePropNativeComponentView\\",
validAttributes: {
thumbImage: {
process: require('react-native/Libraries/Image/resolveAssetSource')
process: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Image/resolveAssetSource'))
}
}
};
@@ -503,7 +503,7 @@ export const __INTERNAL_VIEW_CONFIG = {
uiViewClassName: \\"MultiNativePropNativeComponentView\\",
validAttributes: {
thumbImage: {
process: require('react-native/Libraries/Image/resolveAssetSource')
process: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Image/resolveAssetSource'))
},
color: {
process: require('react-native/Libraries/StyleSheet/processColor').default
@@ -75,7 +75,7 @@ function getReactDiffProcessValue(typeAnnotation: PropTypeAnnotation) {
);
case 'ImageSourcePrimitive':
return expression(
`{ process: require('react-native/Libraries/Image/resolveAssetSource') }`,
"{ process: ((req) => 'default' in req ? req.default : req)(require('react-native/Libraries/Image/resolveAssetSource')) }",
);
case 'ImageRequestPrimitive':
throw new Error('ImageRequest should not be used in props');
@@ -590,7 +590,7 @@ export const __INTERNAL_VIEW_CONFIG = {
uiViewClassName: \\"ImagePropNativeComponent\\",
validAttributes: {
thumbImage: {
process: require('react-native/Libraries/Image/resolveAssetSource')
process: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Image/resolveAssetSource'))
}
}
};
@@ -788,7 +788,7 @@ export const __INTERNAL_VIEW_CONFIG = {
uiViewClassName: \\"ImageColorPropNativeComponent\\",
validAttributes: {
thumbImage: {
process: require('react-native/Libraries/Image/resolveAssetSource')
process: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Image/resolveAssetSource'))
},
color: {
process: require('react-native/Libraries/StyleSheet/processColor').default