iOS: <Canvas opaque> has no effect; MetalWindowContext forces the CAMetalLayer non-opaque (2.12.0)
Description
On iOS (Ganesh/Metal), <Canvas opaque> has no effect: the canvas's CAMetalLayer is always non-opaque, so Core Animation blends it even when it covers its bounds.
In 2.12.0:
apple/MetalWindowContext.mmsets_layer.opaque = false;in the constructor.RNSkMetalCanvasProvider::setSizebuilds a new window context on every resize, so any value set earlier is overwritten each time.apple/SkiaUIView.mm'ssetOpaque:stores_opaqueand does nothing else. Nothing ever reads_opaque.
Repro
import { Canvas, Fill } from "@shopify/react-native-skia";
export default function App() {
return (
<Canvas style={{ flex: 1 }} opaque>
<Fill color="#1a4d33" />
</Canvas>
);
}Expected: the canvas's CAMetalLayer has opaque == YES. Actual: it is NO, as the constructor above sets it on every window context, so Core Animation blends the layer (e.g. visible with the simulator's Debug > Color Blended Layers).
Suggested fix
Stop forcing the value in the window context, and let each view apply its own _opaque to its layer, both on mount and when the prop changes:
--- a/apple/MetalWindowContext.mm
+++ b/apple/MetalWindowContext.mm
@@ -18,7 +18,6 @@
#pragma clang diagnostic pop
_layer.framebufferOnly = NO;
_layer.device = device;
- _layer.opaque = false;
#if !TARGET_OS_OSX
_layer.contentsScale = [UIScreen mainScreen].scale;
#else
--- a/apple/SkiaUIView.mm
+++ b/apple/SkiaUIView.mm
@@ -71,6 +71,7 @@
throw std::runtime_error(
"Expected Skia view implementation, got nullptr.");
}
+ _impl->getLayer().opaque = _opaque;
[self.layer addSublayer:_impl->getLayer()];
if (_nativeId != 0) {
_manager->setSkiaView(_nativeId, _impl->getDrawView());
@@ -161,6 +162,9 @@
- (void)setOpaque:(bool)opaque {
_opaque = opaque;
+ if (_impl != nullptr) {
+ _impl->getLayer().opaque = opaque;
+ }
}CAMetalLayer defaults to opaque = YES, so the mount-time assignment is what keeps the default opaque={false} canvases transparent after the forced line is removed.
We apply this as a patch-package patch. With it, a Release build on an iOS 26.5 simulator (Xcode on GitHub's macos-latest) compiles, and screenshots of a full-screen opaque canvas, taken after it has resized from portrait to landscape bounds, show no black band or uncovered region; the other, non-opaque canvases in the app render unchanged.
Version
@shopify/react-native-skia 2.12.0, React Native New Architecture (Fabric), iOS simulator.
Source: Shopify/react-native-skia