Skip to content

Commit 4f0a11c

Browse files
committed
Update to support the new context option from SDWebImage 5.5.0, deprecated the old one
1 parent 3a826f0 commit 4f0a11c

File tree

6 files changed

+27
-10
lines changed

6 files changed

+27
-10
lines changed

Cartfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
github "SDWebImage/SDWebImage" ~> 5.0
1+
github "SDWebImage/SDWebImage" ~> 5.5

Example/SDWebImageSVGCoder/SDViewController.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ - (void)viewDidLoad
3131
UIImageView *imageView1 = [[UIImageView alloc] init];
3232
imageView1.frame = CGRectMake(0, 0, screenSize.width, screenSize.height / 2);
3333
imageView1.contentMode = UIViewContentModeScaleAspectFit;
34+
imageView1.clipsToBounds = YES;
3435

3536
UIImageView *imageView2 = [[UIImageView alloc] init];
3637
imageView2.frame = CGRectMake(0, screenSize.height / 2, screenSize.width, screenSize.height / 2);
3738
imageView2.contentMode = UIViewContentModeScaleAspectFit;
39+
imageView2.clipsToBounds = YES;
3840

3941
UIImageView *imageView3 = [[UIImageView alloc] init];
4042
imageView3.frame = CGRectMake(screenSize.width - 100, screenSize.height - 100, 100, 100);

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let package = Package(
1717
dependencies: [
1818
// Dependencies declare other packages that this package depends on.
1919
// .package(url: /* package url */, from: "1.0.0"),
20-
.package(url: "https://github.com/SDWebImage/SDWebImage.git", from: "5.1.0")
20+
.package(url: "https://github.com/SDWebImage/SDWebImage.git", from: "5.5.0")
2121
],
2222
targets: [
2323
// Targets are the basic building blocks of a package. A target can define a module or a test suite.

SDWebImageSVGCoder.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ TODO: Add long description of the pod here.
3939
'DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER' => 'NO'
4040
}
4141

42-
s.dependency 'SDWebImage/Core', '~> 5.0'
42+
s.dependency 'SDWebImage/Core', '~> 5.5'
4343
end

SDWebImageSVGCoder/Classes/SDImageSVGCoder.m

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,36 @@ - (UIImage *)decodedImageWithData:(NSData *)data options:(SDImageCoderOptions *)
8181
BOOL prefersBitmap = NO;
8282
CGSize imageSize = CGSizeZero;
8383
BOOL preserveAspectRatio = YES;
84+
85+
#pragma clang diagnostic push
86+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
8487
// Parse args
8588
SDWebImageContext *context = options[SDImageCoderWebImageContext];
86-
if (context[SDWebImageContextSVGPrefersBitmap]) {
87-
prefersBitmap = [context[SDWebImageContextSVGPrefersBitmap] boolValue];
88-
}
8989
if (context[SDWebImageContextSVGImageSize]) {
90+
prefersBitmap = YES;
9091
NSValue *sizeValue = context[SDWebImageContextSVGImageSize];
9192
#if SD_MAC
9293
imageSize = sizeValue.sizeValue;
9394
#else
9495
imageSize = sizeValue.CGSizeValue;
9596
#endif
97+
} else if (options[SDImageCoderDecodeThumbnailPixelSize]) {
98+
prefersBitmap = YES;
99+
NSValue *sizeValue = options[SDImageCoderDecodeThumbnailPixelSize];
100+
#if SD_MAC
101+
imageSize = sizeValue.sizeValue;
102+
#else
103+
imageSize = sizeValue.CGSizeValue;
104+
#endif
105+
} else if (context[SDWebImageContextSVGPrefersBitmap]) {
106+
prefersBitmap = [context[SDWebImageContextSVGPrefersBitmap] boolValue];
96107
}
97108
if (context[SDWebImageContextSVGImagePreserveAspectRatio]) {
98109
preserveAspectRatio = [context[SDWebImageContextSVGImagePreserveAspectRatio] boolValue];
110+
} else if (options[SDImageCoderDecodePreserveAspectRatio]) {
111+
preserveAspectRatio = [context[SDImageCoderDecodePreserveAspectRatio] boolValue];
99112
}
113+
#pragma clang diagnostic pop
100114

101115
UIImage *image;
102116
if (!prefersBitmap && [self.class supportsVectorSVGImage]) {

SDWebImageSVGCoder/Classes/SDWebImageSVGCoderDefine.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@
1414
/**
1515
A BOOL value which specify whether we prefer the actual bitmap representation instead of vector representation for SVG image. This is because the UIImage on iOS 13+ (NSImage on macOS 10.15+) can use the vector image format, which support dynamic scale without losing any detail. However, for some image processing logic, user may need the actual bitmap representation to manage pixels. (NSNumber)
1616
If you don't provide this value, use NO for default value and prefer the vector format when possible.
17+
@note Deprecated, use `SDWebImageContextImageThumbnailPixelSize`. Pass CGSize.zero means the viewBox size of SVG.
1718
*/
18-
FOUNDATION_EXPORT SDWebImageContextOption _Nonnull const SDWebImageContextSVGPrefersBitmap API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0));
19+
FOUNDATION_EXPORT SDWebImageContextOption _Nonnull const SDWebImageContextSVGPrefersBitmap API_DEPRECATED_WITH_REPLACEMENT("SDWebImageContextImageThumbnailPixelSize", macos(10.15, 10.15), ios(13.0, 13.0), watchos(6.0, 6.0), tvos(13.0, 13.0));
1920

2021
/**
2122
A CGSize raw value which specify the desired SVG image size during image loading. Because vector image like SVG format, may not contains a fixed size, or you want to get a larger size bitmap representation UIImage. (NSValue)
22-
If you don't provide this value, use viewBox size of SVG for default value;
23+
If you don't provide this value, use viewBox size of SVG for default value.
2324
*/
24-
FOUNDATION_EXPORT SDWebImageContextOption _Nonnull const SDWebImageContextSVGImageSize API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0));
25+
FOUNDATION_EXPORT SDWebImageContextOption _Nonnull const SDWebImageContextSVGImageSize API_DEPRECATED_WITH_REPLACEMENT("SDWebImageContextImageThumbnailPixelSize", macos(10.15, 10.15), ios(13.0, 13.0), watchos(6.0, 6.0), tvos(13.0, 13.0));
2526

2627
/**
2728
A BOOL value which specify the whether SVG image should keep aspect ratio during image loading. Because when you specify image size via `SDWebImageContextSVGImageSize`, we need to know whether to keep aspect ratio or not when image size aspect ratio is not equal to SVG viewBox size aspect ratio. (NSNumber)
2829
If you don't provide this value, use YES for default value.
2930
*/
30-
FOUNDATION_EXPORT SDWebImageContextOption _Nonnull const SDWebImageContextSVGImagePreserveAspectRatio API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0));
31+
FOUNDATION_EXPORT SDWebImageContextOption _Nonnull const SDWebImageContextSVGImagePreserveAspectRatio API_DEPRECATED_WITH_REPLACEMENT("SDWebImageContextImagePreserveAspectRatio", macos(10.15, 10.15), ios(13.0, 13.0), watchos(6.0, 6.0), tvos(13.0, 13.0));

0 commit comments

Comments
 (0)