react-native-macos/packages/react-native
Saad Najmi db89ff48df
cherrypick: Bring changes to improve our RCTUIGraphicsImageRenderer shim (#2219)
* Rename `RCTUIGraphicsImageRenderer` to `RCTMakeUIGraphicsImageRenderer` (#46772)

Summary:
Because `UIGraphicsImageRenderer` doesn't exist on macOS, I need to shim it for React Native macOS (See https://github.com/microsoft/react-native-macos/pull/2209). I planned to use the name `RCTUIGraphicsImageRenderer`. However.. it seems that is used by a static helper function in `RCTBorderDrawing.m`. So.. let's rename it? The function is just a helper method to make an instance of the class, so I think the name `RCTMakeUIGraphicsImageRenderer` is slightly more idiomatic anyway.

This method is not public, so it should not break the public API of React Native.

[IOS] [CHANGED] - Rename `RCTUIGraphicsImageRenderer` to `RCTMakeUIGraphicsImageRenderer`

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

Test Plan: CI should pass

Reviewed By: joevilches

Differential Revision: D63765490

Pulled By: cipolleschi

fbshipit-source-id: de68dce0f92ec249ea8586dbf7b9ba34a8476074

* fix(iOS): Replace uses of `CGColorRef` with UIColor to avoid manual memory management (#46847)

Summary:
Update React Native on iOS to do less manual memory management, by replacing uses of `CGColorRef` with `UIColor`, and only calling `UIColor.CGColor` when needed. This results in much less manual memory management, which is probably a good thing in 2024 :D. The downside is there is a breaking change: the signature of a method in `RCTBorderDrawing` changes.

This is a followup to https://github.com/facebook/react-native/issues/46797 . After that PR merged and I tested merging React Native macOS to the `0.76-stable` branch cut commit again, I saw even more places I needed to manually call `CGColorRetain` / `CGColorRelease`. The reason is due to React Native macOS specifics (explained below) and I could update React Native macOS to not need these changes, but I thought I would at least throw up a PR to propose the changes, as it may be good to move away from using Core Graphics' C base API as much as possible.

With https://github.com/microsoft/react-native-macos/pull/2209 , I wrote a shim of [UIGraphicsImageRenderer](https://developer.apple.com/documentation/uikit/uigraphicsimagerenderer) for macOS. The main difference is my shim calls the NSImage API [imageWithSize:flipped:drawingHandler:](https://developer.apple.com/documentation/appkit/nsimage/1519860-imagewithsize?language=objc) to shim the UIGraphicsImageRenderer API [imageWithData:](https://developer.apple.com/documentation/uikit/uiimage/1624137-imagewithdata). The difference between the two is that the macOS API copies the block, and executes it when Appkit is about to draw the image, while the iOS API executes the block right away. Because of this, I think I am hitting way more places where `CGColorRef` variables needed to be retained / released. Additionally, I hit more of them when I merge to the 0.76 branch cut commit (this is why I didn't catch it with https://github.com/facebook/react-native/issues/46797).

Given this constraint, I have a couple of options:
1. Refactor my macOS shim to use the deprecated API [[NSImage lockFocus]](https://developer.apple.com/documentation/appkit/nsimage/1519891-lockfocus)
    - I am not a fan of this because `lockFocus` was deprecated for `imageWithSize:flipped:drawingHandler:`
2. Refactor my macOS shim to do what we used to do: Create a CGContext manually and write it to an image
    - This is probably OK. Relies on less Appkit specifics, and potentially gives more control to RN on the rendering layer, which I recall lenaic told me is better for Fabric)
3. Refactor React Native to avoid CGColorRef altogether, and use `UIColor` (which ARC will memory manage for us) as much as possible.
    - This is the approach of this PR and my preferred approach. The downside is this changes the signature of some of the methods in `RCTBorderDrawing` which is a breaking change. I've seen other PRs do this, so maybe its OK?

[IOS] [BREAKING] -  Replace uses of `CGColorRef` with UIColor to avoid manual memory management

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

Test Plan: Launching RNTester's View example (which tests a lot of the border / outline / shadow rendering) does not crash for me on both iOS and macOS.

Reviewed By: NickGerleman

Differential Revision: D63989547

Pulled By: joevilches

fbshipit-source-id: 5e85e17567e3dd8b4b0388452398954ad2e02464

* Followup fixes

* Remove extra scaleFactor argument that is now unused

* Further reduce diffs related to scaleFactor

* fix typos and dead code
2024-10-13 14:15:55 -05:00
..
Libraries Multi line text view key handling: add check for first responder (#2215) 2024-10-08 22:23:54 -05:00
React cherrypick: Bring changes to improve our RCTUIGraphicsImageRenderer shim (#2219) 2024-10-13 14:15:55 -05:00
ReactAndroid Merge commit '6f7eae5c583090bd62ca60a4c3170445e5a0a751' into main 2024-08-22 23:08:52 -07:00
ReactApple
ReactCommon Merge commit '6f7eae5c583090bd62ca60a4c3170445e5a0a751' into main 2024-08-22 23:08:52 -07:00
android
flow
gradle
jest
local-cli fix: Remove flipper config from the Podfile template (#2195) 2024-09-20 08:20:27 -07:00
scripts Merge commit '6f7eae5c583090bd62ca60a4c3170445e5a0a751' into main 2024-08-22 23:08:52 -07:00
sdks/hermes-engine Merge commit '6f7eae5c583090bd62ca60a4c3170445e5a0a751' into main 2024-08-22 23:08:52 -07:00
src Merge commit '6f7eae5c583090bd62ca60a4c3170445e5a0a751' into main 2024-08-22 23:08:52 -07:00
template Merge commit '6f7eae5c583090bd62ca60a4c3170445e5a0a751' into main 2024-08-22 23:08:52 -07:00
third-party-podspecs Merge commit '6f7eae5c583090bd62ca60a4c3170445e5a0a751' into main 2024-08-22 23:08:52 -07:00
types Merge commit '6f7eae5c583090bd62ca60a4c3170445e5a0a751' into main 2024-08-22 23:08:52 -07:00
LICENSE
React-Core.podspec
React.podspec
build.gradle.kts
cli.js
gradle.properties
index.js Merge commit '6f7eae5c583090bd62ca60a4c3170445e5a0a751' into main 2024-08-22 23:08:52 -07:00
interface.js
jest-preset.js
metro.config.js
package.json fix: `local-cli` is missing from published package (#2182) 2024-08-30 12:21:46 -07:00
react-native.config.js Merge commit '6f7eae5c583090bd62ca60a4c3170445e5a0a751' into main 2024-08-22 23:08:52 -07:00
rn-get-polyfills.js
settings.gradle.kts
template.config.js