Skip to content

Commit

Permalink
Merge pull request #1563 from Shopify/fix/1558-fix-format-for-ios
Browse files Browse the repository at this point in the history
Fixed issue with snapshots being in wrong colors on iOS
  • Loading branch information
chrfalch authored May 12, 2023
2 parents 6e332ca + 1e0ae5b commit f20240e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion package/ios/RNSkia-iOS/ViewScreenshotService.mm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ - (instancetype)initWithUiManager:(RCTUIManager *)uiManager {
UIGraphicsImageRendererFormat *format =
[UIGraphicsImageRendererFormat defaultFormat];
format.opaque = NO;

// Explicitly ask for the standard format to get ARGB 32bits and not 64bits.
if (@available(iOS 12.0, *)) {
format.preferredRange = UIGraphicsImageRendererFormatRangeStandard;
} else {
// Fallback on earlier versions
format.prefersExtendedRange = false;
}

UIGraphicsImageRenderer *renderer =
[[UIGraphicsImageRenderer alloc] initWithSize:size format:format];

Expand Down Expand Up @@ -68,9 +77,12 @@ - (instancetype)initWithUiManager:(RCTUIManager *)uiManager {
(void *)dataRef);

// Make SkImageInfo
// We're using kBGRA_8888_SkColorType since this is what we get when the
// UIGraphicsImageRenderer uses the standard format (the extended is using
// 64bits so it is not suitable for us).
SkImageInfo info =
SkImageInfo::Make(static_cast<int>(width), static_cast<int>(height),
kRGBA_8888_SkColorType, kPremul_SkAlphaType);
kBGRA_8888_SkColorType, kPremul_SkAlphaType);

// ... and then create the SkImage itself!
return SkImage::MakeRasterData(info, skData, bytesPerRow);
Expand Down

0 comments on commit f20240e

Please sign in to comment.