Merge pull request #2753 from dreampiggy/feature_supports_dynamic_indicator

Feature supports dynamic style indicator for iOS 13, fix indicator color on macOS 10.14+
This commit is contained in:
DreamPiggy 2019-06-14 12:53:03 +08:00 committed by GitHub
commit 4613ad7c8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 0 deletions

View File

@ -35,6 +35,7 @@
self.imageView1.sd_imageIndicator = SDWebImageProgressIndicator.defaultIndicator;
[self.imageView1 sd_setImageWithURL:[NSURL URLWithString:@"https://raw.githubusercontent.com/recurser/exif-orientation-examples/master/Landscape_2.jpg"] placeholderImage:nil options:SDWebImageProgressiveLoad];
// NSImageView + Animated Image
self.imageView2.sd_imageIndicator = SDWebImageActivityIndicator.largeIndicator;
[self.imageView2 sd_setImageWithURL:[NSURL URLWithString:@"https:raw.githubusercontent.com/onevcat/APNGKit/master/TestImages/APNG-cube.apng"]];
// SDAnimatedImageView + Static Image
[self.imageView3 sd_setImageWithURL:[NSURL URLWithString:@"https://nr-platform.s3.amazonaws.com/uploads/platform/published_extension/branding_icon/275/AmazonS3.png"]];

View File

@ -66,6 +66,7 @@
*/
@interface SDWebImageActivityIndicator (Conveniences)
/// These indicator use the fixed color without dark mode support
/// gray-style activity indicator
@property (nonatomic, class, nonnull, readonly) SDWebImageActivityIndicator *grayIndicator;
/// large gray-style activity indicator
@ -74,6 +75,11 @@
@property (nonatomic, class, nonnull, readonly) SDWebImageActivityIndicator *whiteIndicator;
/// large white-style activity indicator
@property (nonatomic, class, nonnull, readonly) SDWebImageActivityIndicator *whiteLargeIndicator;
/// 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;
/// medium activity indicator
@property (nonatomic, class, nonnull, readonly) SDWebImageActivityIndicator *mediumIndicator;
@end

View File

@ -14,6 +14,16 @@
#import <QuartzCore/QuartzCore.h>
#endif
#if SD_UIKIT
#if __IPHONE_13_0 || __TVOS_13_0 || __MAC_10_15
// Xcode 11
#else
// Supports Xcode 9 && 10 users, for those users, define these enum
static NSInteger UIActivityIndicatorViewStyleMedium = 100;
static NSInteger UIActivityIndicatorViewStyleLarge = 101;
#endif
#endif
#pragma mark - Activity Indicator
@interface SDWebImageActivityIndicator ()
@ -83,6 +93,8 @@
#else
indicator.indicatorView.color = [UIColor colorWithWhite:0 alpha:0.45]; // Color from `UIActivityIndicatorViewStyleGray`
#endif
#else
indicator.indicatorView.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua]; // Disable dark mode support
#endif
return indicator;
}
@ -94,6 +106,7 @@
indicator.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
indicator.indicatorView.color = grayColor;
#else
indicator.indicatorView.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua]; // Disable dark mode support
indicator.indicatorView.controlSize = NSControlSizeRegular;
#endif
[indicator.indicatorView sizeToFit];
@ -105,6 +118,7 @@
#if SD_UIKIT
indicator.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
#else
indicator.indicatorView.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua]; // Disable dark mode support
CIFilter *lighten = [CIFilter filterWithName:@"CIColorControls"];
[lighten setDefaults];
[lighten setValue:@(1) forKey:kCIInputBrightnessKey];
@ -118,12 +132,43 @@
#if SD_UIKIT
indicator.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
#else
indicator.indicatorView.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua]; // Disable dark mode support
indicator.indicatorView.controlSize = NSControlSizeRegular;
[indicator.indicatorView sizeToFit];
#endif
return indicator;
}
+ (SDWebImageActivityIndicator *)largeIndicator {
SDWebImageActivityIndicator *indicator = [SDWebImageActivityIndicator new];
#if SD_UIKIT
if (@available(iOS 13.0, tvOS 13.0, *)) {
indicator.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleLarge;
} else {
indicator.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
}
#else
indicator.indicatorView.controlSize = NSControlSizeRegular;
[indicator.indicatorView sizeToFit];
#endif
return indicator;
}
+ (SDWebImageActivityIndicator *)mediumIndicator {
SDWebImageActivityIndicator *indicator = [SDWebImageActivityIndicator new];
#if SD_UIKIT
if (@available(iOS 13.0, tvOS 13.0, *)) {
indicator.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleMedium;
} else {
indicator.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
}
#else
indicator.indicatorView.controlSize = NSControlSizeSmall;
[indicator.indicatorView sizeToFit];
#endif
return indicator;
}
@end
#pragma mark - Progress Indicator