Added support for visionOS using platform macro detection
The scale using traitCollection.displayScale This only change source code
This commit is contained in:
parent
2db2c7ad5b
commit
a797da71ce
|
@ -54,9 +54,15 @@ static CGFloat SDImageScaleFromPath(NSString *string) {
|
|||
|
||||
#if __has_include(<UIKit/UITraitCollection.h>)
|
||||
+ (instancetype)imageNamed:(NSString *)name inBundle:(NSBundle *)bundle compatibleWithTraitCollection:(UITraitCollection *)traitCollection {
|
||||
#if SD_VISION
|
||||
if (!traitCollection) {
|
||||
traitCollection = UITraitCollection.currentTraitCollection;
|
||||
}
|
||||
#else
|
||||
if (!traitCollection) {
|
||||
traitCollection = UIScreen.mainScreen.traitCollection;
|
||||
}
|
||||
#endif
|
||||
CGFloat scale = traitCollection.displayScale;
|
||||
return [self imageNamed:name inBundle:bundle scale:scale];
|
||||
}
|
||||
|
|
|
@ -72,7 +72,9 @@
|
|||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
- (SDGraphicsImageRendererFormatRange)preferredRange {
|
||||
#if SD_UIKIT
|
||||
#if SD_VISION
|
||||
return (SDGraphicsImageRendererFormatRange)self.uiformat.preferredRange;
|
||||
#elif SD_UIKIT
|
||||
if (@available(iOS 10.0, tvOS 10.10, *)) {
|
||||
if (@available(iOS 12.0, tvOS 12.0, *)) {
|
||||
return (SDGraphicsImageRendererFormatRange)self.uiformat.preferredRange;
|
||||
|
@ -93,7 +95,9 @@
|
|||
}
|
||||
|
||||
- (void)setPreferredRange:(SDGraphicsImageRendererFormatRange)preferredRange {
|
||||
#if SD_UIKIT
|
||||
#if SD_VISION
|
||||
self.uiformat.preferredRange = (UIGraphicsImageRendererFormatRange)preferredRange;
|
||||
#elif SD_UIKIT
|
||||
if (@available(iOS 10.0, tvOS 10.10, *)) {
|
||||
if (@available(iOS 12.0, tvOS 12.0, *)) {
|
||||
self.uiformat.preferredRange = (UIGraphicsImageRendererFormatRange)preferredRange;
|
||||
|
@ -127,7 +131,9 @@
|
|||
self.uiformat = uiformat;
|
||||
} else {
|
||||
#endif
|
||||
#if SD_WATCH
|
||||
#if SD_VISION
|
||||
CGFloat screenScale = UITraitCollection.currentTraitCollection.displayScale;
|
||||
#elif SD_WATCH
|
||||
CGFloat screenScale = [WKInterfaceDevice currentDevice].screenScale;
|
||||
#elif SD_UIKIT
|
||||
CGFloat screenScale = [UIScreen mainScreen].scale;
|
||||
|
@ -167,7 +173,9 @@
|
|||
self.uiformat = uiformat;
|
||||
} else {
|
||||
#endif
|
||||
#if SD_WATCH
|
||||
#if SD_VISION
|
||||
CGFloat screenScale = UITraitCollection.currentTraitCollection.displayScale;
|
||||
#elif SD_WATCH
|
||||
CGFloat screenScale = [WKInterfaceDevice currentDevice].screenScale;
|
||||
#elif SD_UIKIT
|
||||
CGFloat screenScale = [UIScreen mainScreen].scale;
|
||||
|
|
|
@ -23,7 +23,7 @@ SDImageCoderOptions * _Nonnull SDGetDecodeOptionsFromContext(SDWebImageContext *
|
|||
NSValue *thumbnailSizeValue;
|
||||
BOOL shouldScaleDown = SD_OPTIONS_CONTAINS(options, SDWebImageScaleDownLargeImages);
|
||||
NSNumber *scaleDownLimitBytesValue = context[SDWebImageContextImageScaleDownLimitBytes];
|
||||
if (!scaleDownLimitBytesValue && shouldScaleDown) {
|
||||
if (scaleDownLimitBytesValue == nil && shouldScaleDown) {
|
||||
// Use the default limit bytes
|
||||
scaleDownLimitBytesValue = @(SDImageCoderHelper.defaultScaleDownLimitBytes);
|
||||
}
|
||||
|
|
|
@ -47,6 +47,12 @@
|
|||
#define SD_WATCH 0
|
||||
#endif
|
||||
|
||||
// Supports Xcode 14 to suppress warning
|
||||
#ifdef TARGET_OS_VISION
|
||||
#if TARGET_OS_VISION
|
||||
#define SD_VISION 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if SD_MAC
|
||||
#import <AppKit/AppKit.h>
|
||||
|
|
|
@ -23,20 +23,7 @@ inline CGFloat SDImageScaleFactorForKey(NSString * _Nullable key) {
|
|||
if (!key) {
|
||||
return scale;
|
||||
}
|
||||
// Check if target OS support scale
|
||||
#if SD_WATCH
|
||||
if ([[WKInterfaceDevice currentDevice] respondsToSelector:@selector(screenScale)])
|
||||
#elif SD_UIKIT
|
||||
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
|
||||
#elif SD_MAC
|
||||
NSScreen *mainScreen = nil;
|
||||
if (@available(macOS 10.12, *)) {
|
||||
mainScreen = [NSScreen mainScreen];
|
||||
} else {
|
||||
mainScreen = [NSScreen screens].firstObject;
|
||||
}
|
||||
if ([mainScreen respondsToSelector:@selector(backingScaleFactor)])
|
||||
#endif
|
||||
// Now all OS supports retina display scale system
|
||||
{
|
||||
// a@2x.png -> 8
|
||||
if (key.length >= 8) {
|
||||
|
|
|
@ -104,11 +104,12 @@ static void * SDWebImageDownloaderContext = &SDWebImageDownloaderContext;
|
|||
_URLOperations = [NSMutableDictionary new];
|
||||
NSMutableDictionary<NSString *, NSString *> *headerDictionary = [NSMutableDictionary dictionary];
|
||||
NSString *userAgent = nil;
|
||||
#if SD_UIKIT
|
||||
// User-Agent Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43
|
||||
#if SD_VISION
|
||||
userAgent = [NSString stringWithFormat:@"%@/%@ (%@; visionOS %@; Scale/%0.2f)", [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleExecutableKey] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleIdentifierKey], [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], UITraitCollection.currentTraitCollection.displayScale];
|
||||
#elif SD_UIKIT
|
||||
userAgent = [NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleExecutableKey] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleIdentifierKey], [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], [[UIScreen mainScreen] scale]];
|
||||
#elif SD_WATCH
|
||||
// User-Agent Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43
|
||||
userAgent = [NSString stringWithFormat:@"%@/%@ (%@; watchOS %@; Scale/%0.2f)", [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleExecutableKey] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleIdentifierKey], [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleVersionKey], [[WKInterfaceDevice currentDevice] model], [[WKInterfaceDevice currentDevice] systemVersion], [[WKInterfaceDevice currentDevice] screenScale]];
|
||||
#elif SD_MAC
|
||||
userAgent = [NSString stringWithFormat:@"%@/%@ (Mac OS X %@)", [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleExecutableKey] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleIdentifierKey], [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleVersionKey], [[NSProcessInfo processInfo] operatingSystemVersionString]];
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
*/
|
||||
@interface SDWebImageActivityIndicator (Conveniences)
|
||||
|
||||
#if !SD_VISION
|
||||
/// These indicator use the fixed color without dark mode support
|
||||
/// gray-style activity indicator
|
||||
@property (nonatomic, class, nonnull, readonly) SDWebImageActivityIndicator *grayIndicator;
|
||||
|
@ -75,6 +76,7 @@
|
|||
@property (nonatomic, class, nonnull, readonly) SDWebImageActivityIndicator *whiteIndicator;
|
||||
/// large white-style activity indicator
|
||||
@property (nonatomic, class, nonnull, readonly) SDWebImageActivityIndicator *whiteLargeIndicator;
|
||||
#endif
|
||||
/// These indicator use the system style, supports dark mode if available (iOS 13+/macOS 10.14+)
|
||||
/// large activity indicator
|
||||
@property (nonatomic, class, nonnull, readonly) SDWebImageActivityIndicator *largeIndicator;
|
||||
|
|
|
@ -41,7 +41,17 @@
|
|||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
- (void)commonInit {
|
||||
self.indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
|
||||
#if SD_VISION
|
||||
UIActivityIndicatorViewStyle style = UIActivityIndicatorViewStyleMedium;
|
||||
#else
|
||||
UIActivityIndicatorViewStyle style;
|
||||
if (@available(iOS 13.0, tvOS 13.0, *)) {
|
||||
style = UIActivityIndicatorViewStyleMedium;
|
||||
} else {
|
||||
style = UIActivityIndicatorViewStyleWhite;
|
||||
}
|
||||
#endif
|
||||
self.indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:style];
|
||||
self.indicatorView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin;
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
|
@ -79,6 +89,7 @@
|
|||
|
||||
@implementation SDWebImageActivityIndicator (Conveniences)
|
||||
|
||||
#if !SD_VISION
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
+ (SDWebImageActivityIndicator *)grayIndicator {
|
||||
|
@ -134,10 +145,13 @@
|
|||
#endif
|
||||
return indicator;
|
||||
}
|
||||
#endif
|
||||
|
||||
+ (SDWebImageActivityIndicator *)largeIndicator {
|
||||
SDWebImageActivityIndicator *indicator = [SDWebImageActivityIndicator new];
|
||||
#if SD_UIKIT
|
||||
#if SD_VISION
|
||||
indicator.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleLarge;
|
||||
#elif SD_UIKIT
|
||||
if (@available(iOS 13.0, tvOS 13.0, *)) {
|
||||
indicator.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleLarge;
|
||||
} else {
|
||||
|
@ -152,7 +166,9 @@
|
|||
|
||||
+ (SDWebImageActivityIndicator *)mediumIndicator {
|
||||
SDWebImageActivityIndicator *indicator = [SDWebImageActivityIndicator new];
|
||||
#if SD_UIKIT
|
||||
#if SD_VISION
|
||||
indicator.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleMedium;
|
||||
#elif SD_UIKIT
|
||||
if (@available(iOS 13.0, tvOS 13.0, *)) {
|
||||
indicator.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleMedium;
|
||||
} else {
|
||||
|
|
|
@ -13,7 +13,9 @@ static NSArray *SDBundlePreferredScales(void) {
|
|||
static NSArray *scales;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
#if SD_WATCH
|
||||
#if SD_VISION
|
||||
CGFloat screenScale = UITraitCollection.currentTraitCollection.displayScale;
|
||||
#elif SD_WATCH
|
||||
CGFloat screenScale = [WKInterfaceDevice currentDevice].screenScale;
|
||||
#elif SD_UIKIT
|
||||
CGFloat screenScale = [UIScreen mainScreen].scale;
|
||||
|
|
Loading…
Reference in New Issue