react-native icon indicating copy to clipboard operation
react-native copied to clipboard

feature: Update `Image.getSize/getSizeWithHeaders ` methods to return a promise

Open retyui opened this issue 2 years ago • 5 comments

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:

  1. ts: New test cases added in typescript tests
  2. 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.js b. node_modules/react-native/Libraries/Image/Image.ios.js

retyui avatar Feb 06 '24 16:02 retyui

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.

retyui avatar Feb 07 '24 10:02 retyui

/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.

cipolleschi avatar Feb 07 '24 14:02 cipolleschi

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

analysis-bot avatar Feb 07 '24 16:02 analysis-bot

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Feb 19 '24 14:02 facebook-github-bot

the Facebook Internal - Builds & Tests job has failed, do I need to change smth? @cipolleschi

retyui avatar Feb 26 '24 08:02 retyui

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... ¯_(ツ)_/¯ )

cipolleschi avatar Feb 26 '24 17:02 cipolleschi

This pull request was successfully merged by @retyui in 2c1bcbac81dc4506196c000d72d52b7e9c1c1ec1.

When will my fix make it into a release? | Upcoming Releases

github-actions[bot] avatar Feb 27 '24 09:02 github-actions[bot]