feature: Update `Image.getSize/getSizeWithHeaders ` methods to return a promise
Summary:
Image.getSize/getSizeWithHeaders are still working in old fashioned "callback" way
Image.getSize(uri, function success(width,height) { }, function failure(){ } ); // undefined
Image.getSizeWithHeaders(uri, headers, function success(width,height) { }, function failure(){ } ); // undefined
But in 2024 more developers prefer use async/await syntax for asynchronous operations
So, in this PR I added support for Promise API with backward compatibility, modern way:
Image.getSize(uri).then(({width,height}) => { }); // Promise
Image.getSizeWithHeaders(uri, headers).then(({width,height}) => { }); // Promise
Changelog:
[GENERAL] [ADDED] - Image.getSize/getSizeWithHeaders method returns a promise if you don't pass a success callback
Test Plan:
- ts: New test cases added in typescript tests
- runtime: you can create a new project and put code from this PR into the next files
a.
node_modules/react-native/Libraries/Image/Image.android.jsb.node_modules/react-native/Libraries/Image/Image.ios.js
Query: What might cause the next build failure ?
In file included from /root/react-native/packages/react-native/ReactAndroid/build/generated/source/codegen/jni/react/renderer/components/rncore/rncoreJSI-generated.cpp:10:
/root/react-native/packages/react-native/ReactAndroid/build/generated/source/codegen/jni/react/renderer/components/rncore/rncoreJSI.h:4503:60: error: redefinition of 'ImageLoaderBaseImageSize'
struct [[deprecated("Use ImageLoaderImageSize instead.")]] ImageLoaderBaseImageSize {
^
/root/react-native/packages/react-native/ReactAndroid/build/generated/source/codegen/jni/react/renderer/components/rncore/rncoreJSI.h:4320:60: note: previous definition is here
struct [[deprecated("Use ImageLoaderImageSize instead.")]] ImageLoaderBaseImageSize {
^
/root/react-native/packages/react-native/ReactAndroid/build/generated/source/codegen/jni/react/renderer/components/rncore/rncoreJSI.h:4512:68: error: redefinition of 'ImageLoaderBaseImageSizeBridging'
struct [[deprecated("Use ImageLoaderImageSizeBridging instead.")]] ImageLoaderBaseImageSizeBridging {
^
/root/react-native/packages/react-native/ReactAndroid/build/generated/source/codegen/jni/react/renderer/components/rncore/rncoreJSI.h:4329:68: note: previous definition is here
struct [[deprecated("Use ImageLoaderImageSizeBridging instead.")]] ImageLoaderBaseImageSizeBridging {
^
/root/react-native/packages/react-native/ReactAndroid/build/generated/source/codegen/jni/react/renderer/components/rncore/rncoreJSI.h:4548:8: error: redefinition of 'ImageLoaderImageSize'
struct ImageLoaderImageSize {
^
/root/react-native/packages/react-native/ReactAndroid/build/generated/source/codegen/jni/react/renderer/components/rncore/rncoreJSI.h:4365:8: note: previous definition is here
struct ImageLoaderImageSize {
^
/root/react-native/packages/react-native/ReactAndroid/build/generated/source/codegen/jni/react/renderer/components/rncore/rncoreJSI.h:4557:8: error: redefinition of 'ImageLoaderImageSizeBridging'
struct ImageLoaderImageSizeBridging {
^
/root/react-native/packages/react-native/ReactAndroid/build/generated/source/codegen/jni/react/renderer/components/rncore/rncoreJSI.h:4374:8: note: previous definition is here
struct ImageLoaderImageSizeBridging {
^
4 errors generated.
/rebase - this commet will rebase the PR on top of main automatically.
All these changes are JS changes only, there is no reason why the native builds should fail. Let's see if a rebase fixes CI.
| Platform | Engine | Arch | Size (bytes) | Diff |
|---|---|---|---|---|
| android | hermes | arm64-v8a | 17,233,283 | -187 |
| android | hermes | armeabi-v7a | n/a | -- |
| android | hermes | x86 | n/a | -- |
| android | hermes | x86_64 | n/a | -- |
| android | jsc | arm64-v8a | 20,600,121 | +53 |
| android | jsc | armeabi-v7a | n/a | -- |
| android | jsc | x86 | n/a | -- |
| android | jsc | x86_64 | n/a | -- |
Base commit: c1b8f3758083062c650dbe837f3d94057a86d103 Branch: main
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
the Facebook Internal - Builds & Tests job has failed, do I need to change smth? @cipolleschi
I was looking into that. There is an internal E2E test that is failing and I need to understand why. I'll probably look into it tomorrow morning, as the day is almost over and I have another meeting coming up. :( (it's the only test that is failing, all the other signals are green... ¯_(ツ)_/¯ )
This pull request was successfully merged by @retyui in 2c1bcbac81dc4506196c000d72d52b7e9c1c1ec1.
When will my fix make it into a release? | Upcoming Releases