You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Summary:
Needs microsoft#2783 to merge first.
Resolvesmicrosoft#2738
There were a couple of issues with our macOS image rendering code that
caused borders and shadows to not render properly in Fabric:
1. Our shim for `UIGraphicsImageRenderer` on macOS
(`RCTUIGraphicsImageRenderer`) called `[NSImage
imageWithActions:flipped:drawingHandler]`, which would not render the
imade right away but instead when it's about to be displayed (presumably
so that it can generate a proper `CGContext` for the screen the image is
on). This meant that CGImage bitmap would sometimes just return as `0x0`
1. `NSImage` unlike `UIImage` does not have a `CGImage` property, so we
used the method `CGImageForProposedRect:` to get one. Unfortunately,
that returns an autoreleased CGImage, and when we later set that to
RCTViewComponentViews' `layer.contents`, it would not be retained.
This manifested as borders and shadows not rendering, or rendering and
then dissapearing on a resize.
To fix the first issue, apparently we can just call `[image lockFocus]`
and `[image unlockFocus]` in succession to force it to render a bitmap.
To fix the second issue, we need some way to cache the CGImage. I
propose a new class: `RCTUIImage`.
`RCTUIImage`, like `RCTUIView` is a subclass of `NSImage` with some
extra properties and methods to make it more compatible with iOS code.
In our case, we add the extra code to cache a CGImage, with proper
retain and release calls. We can then have `RCTUIGraphicsImageRenderer`
return our new subclass, and update all callers appropiately. The end
result it we can actually remove some diffs, and have our macOS image
handling behave closer to iOS.
While doing this work, I realized our `NSImage` / `UIImage` shims were
kinda messy, and with the new subclass to introduce weird runtime edge
cases. I split out microsoft#2783 to help clean up and clarify what image class
we're using in the rest of the codebase.
While here, I also fixed an issue with clipsToBounds on macOS which was
the final piece to get shadows and borders working.
## Test Plan:
RNTester seems better :)
https://github.com/user-attachments/assets/a5afe150-15ae-4c92-9219-8843aa5362ac
0 commit comments