A framework for building native applications using React
feature: Update `Image.getSize/getSizeWithHeaders ` methods to return a promise (#42895)
Summary:
`Image.getSize/getSizeWithHeaders` are still working in old fashioned "callback" way
```tsx
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:
```tsx
Image.getSize(uri).then(({width,height}) => { }); // Promise
Image.getSizeWithHeaders(uri, headers).then(({width,height}) => { }); // Promise
```
bypass-github-export-checks
## Changelog:
[GENERAL] [ADDED] - `Image.getSize/getSizeWithHeaders` method returns a promise if you don't pass a `success` callback
Pull Request resolved: https://github.com/facebook/react-native/pull/42895
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`
Reviewed By: javache
Differential Revision: D53919431
Pulled By: cipolleschi
fbshipit-source-id: 508b201e17e0ffda2e67aa5292bf9906b88d09c5 D
D N committed
2c1bcbac81dc4506196c000d72d52b7e9c1c1ec1
Parent: 489df72
Committed by Facebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
on 2/27/2024, 9:54:30 AM