From 6a2703f9d01fbf3064ce94d08ecf7067782b4da6 Mon Sep 17 00:00:00 2001 From: liangxuan Date: Wed, 20 Jun 2018 14:27:01 +0800 Subject: [PATCH 1/6] fix --- Classes/IDMPhoto.m | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Classes/IDMPhoto.m b/Classes/IDMPhoto.m index a2959d5c..93522971 100644 --- a/Classes/IDMPhoto.m +++ b/Classes/IDMPhoto.m @@ -138,11 +138,20 @@ - (void)loadUnderlyingImageAndNotify { // Load async from web (using SDWebImageManager) [[SDWebImageManager sharedManager] loadImageWithURL:_photoURL options:SDWebImageRetryFailed progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) { - CGFloat progress = ((CGFloat)receivedSize)/((CGFloat)expectedSize); - - if (self.progressUpdateBlock) { - self.progressUpdateBlock(progress); - } + if ([NSThread isMainThread]) { + CGFloat progress = ((CGFloat)receivedSize)/((CGFloat)expectedSize); + if (self.progressUpdateBlock) { + self.progressUpdateBlock(progress); + } + } else { + __weak typeof(self) weakSelf = self; + dispatch_async(dispatch_get_main_queue(), ^{ + CGFloat progress = ((CGFloat)receivedSize)/((CGFloat)expectedSize); + if (weakSelf.progressUpdateBlock) { + weakSelf.progressUpdateBlock(progress); + } + }); + } } completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) { if (image) { self.underlyingImage = image; From 2dc4d6da93f3a5696821d6c00e0521885d5a2fa4 Mon Sep 17 00:00:00 2001 From: liangxuan Date: Wed, 20 Jun 2018 14:46:00 +0800 Subject: [PATCH 2/6] add git support add git support --- Classes/IDMPhoto.h | 1 - Classes/IDMPhoto.m | 80 ++++++++++++++++-------------- Classes/IDMTapDetectingImageView.h | 5 +- Demo/Podfile | 2 +- IDMPhotoBrowser.podspec | 2 +- 5 files changed, 47 insertions(+), 43 deletions(-) diff --git a/Classes/IDMPhoto.h b/Classes/IDMPhoto.h index f87bd178..44b4a5f0 100644 --- a/Classes/IDMPhoto.h +++ b/Classes/IDMPhoto.h @@ -8,7 +8,6 @@ #import #import "IDMPhotoProtocol.h" -#import // This class models a photo/image and it's caption // If you want to handle photos, caching, decompression diff --git a/Classes/IDMPhoto.m b/Classes/IDMPhoto.m index 93522971..a1df6c20 100644 --- a/Classes/IDMPhoto.m +++ b/Classes/IDMPhoto.m @@ -8,6 +8,7 @@ #import "IDMPhoto.h" #import "IDMPhotoBrowser.h" +#import // Private @interface IDMPhoto () { @@ -34,7 +35,7 @@ - (void)imageLoadingComplete; @implementation IDMPhoto // Properties -@synthesize underlyingImage = _underlyingImage, +@synthesize underlyingImage = _underlyingImage, photoURL = _photoURL, caption = _caption; @@ -54,33 +55,33 @@ + (IDMPhoto *)photoWithURL:(NSURL *)url { + (NSArray *)photosWithImages:(NSArray *)imagesArray { NSMutableArray *photos = [NSMutableArray arrayWithCapacity:imagesArray.count]; - + for (UIImage *image in imagesArray) { if ([image isKindOfClass:[UIImage class]]) { IDMPhoto *photo = [IDMPhoto photoWithImage:image]; [photos addObject:photo]; } } - + return photos; } + (NSArray *)photosWithFilePaths:(NSArray *)pathsArray { NSMutableArray *photos = [NSMutableArray arrayWithCapacity:pathsArray.count]; - + for (NSString *path in pathsArray) { if ([path isKindOfClass:[NSString class]]) { IDMPhoto *photo = [IDMPhoto photoWithFilePath:path]; [photos addObject:photo]; } } - + return photos; } + (NSArray *)photosWithURLs:(NSArray *)urlsArray { NSMutableArray *photos = [NSMutableArray arrayWithCapacity:urlsArray.count]; - + for (id url in urlsArray) { if ([url isKindOfClass:[NSURL class]]) { IDMPhoto *photo = [IDMPhoto photoWithURL:url]; @@ -91,7 +92,7 @@ + (NSArray *)photosWithURLs:(NSArray *)urlsArray { [photos addObject:photo]; } } - + return photos; } @@ -136,29 +137,32 @@ - (void)loadUnderlyingImageAndNotify { [self performSelectorInBackground:@selector(loadImageFromFileAsync) withObject:nil]; } else if (_photoURL) { // Load async from web (using SDWebImageManager) - - [[SDWebImageManager sharedManager] loadImageWithURL:_photoURL options:SDWebImageRetryFailed progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) { + + [[YYWebImageManager sharedManager] requestImageWithURL:_photoURL options:YYWebImageOptionShowNetworkActivity progress:^(NSInteger receivedSize, NSInteger expectedSize) { if ([NSThread isMainThread]) { - CGFloat progress = ((CGFloat)receivedSize)/((CGFloat)expectedSize); - if (self.progressUpdateBlock) { - self.progressUpdateBlock(progress); - } + CGFloat progress = ((CGFloat)receivedSize)/((CGFloat)expectedSize); + if (self.progressUpdateBlock) { + self.progressUpdateBlock(progress); + } } else { __weak typeof(self) weakSelf = self; dispatch_async(dispatch_get_main_queue(), ^{ - CGFloat progress = ((CGFloat)receivedSize)/((CGFloat)expectedSize); - if (weakSelf.progressUpdateBlock) { - weakSelf.progressUpdateBlock(progress); - } + CGFloat progress = ((CGFloat)receivedSize)/((CGFloat)expectedSize); + if (weakSelf.progressUpdateBlock) { + weakSelf.progressUpdateBlock(progress); + } }); } - } completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) { - if (image) { - self.underlyingImage = image; - } - - [self performSelectorOnMainThread:@selector(imageLoadingComplete) withObject:nil waitUntilDone:NO]; - }]; + } transform:^UIImage * _Nullable(UIImage * _Nonnull image, NSURL * _Nonnull url) { + return image; + } completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) { + if (image) { + self.underlyingImage = image; + } + + [self performSelectorOnMainThread:@selector(imageLoadingComplete) withObject:nil waitUntilDone:NO]; + }]; + } else { // Failed - no source self.underlyingImage = nil; @@ -183,7 +187,7 @@ - (void)unloadUnderlyingImage { // System only supports RGB, set explicitly and prevent context error // if the downloaded image is not the supported format CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); - + CGContextRef context = CGBitmapContextCreate(NULL, CGImageGetWidth(imageRef), CGImageGetHeight(imageRef), @@ -195,16 +199,16 @@ - (void)unloadUnderlyingImage { // makes system don't need to do extra conversion when displayed. kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little); CGColorSpaceRelease(colorSpace); - + if ( ! context) { return nil; } - + CGRect rect = (CGRect){CGPointZero, CGImageGetWidth(imageRef), CGImageGetHeight(imageRef)}; CGContextDrawImage(context, rect, imageRef); CGImageRef decompressedImageRef = CGBitmapContextCreateImage(context); CGContextRelease(context); - + UIImage *decompressedImage = [[UIImage alloc] initWithCGImage:decompressedImageRef]; CGImageRelease(decompressedImageRef); return decompressedImage; @@ -215,26 +219,26 @@ - (UIImage *)decodedImageWithImage:(UIImage *)image { // Do not decode animated images return image; } - + CGImageRef imageRef = image.CGImage; CGSize imageSize = CGSizeMake(CGImageGetWidth(imageRef), CGImageGetHeight(imageRef)); CGRect imageRect = (CGRect){.origin = CGPointZero, .size = imageSize}; - + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef); - + int infoMask = (bitmapInfo & kCGBitmapAlphaInfoMask); BOOL anyNonAlpha = (infoMask == kCGImageAlphaNone || infoMask == kCGImageAlphaNoneSkipFirst || infoMask == kCGImageAlphaNoneSkipLast); - + // CGBitmapContextCreate doesn't support kCGImageAlphaNone with RGB. // https://developer.apple.com/library/mac/#qa/qa1037/_index.html if (infoMask == kCGImageAlphaNone && CGColorSpaceGetNumberOfComponents(colorSpace) > 1) { // Unset the old alpha info. bitmapInfo &= ~kCGBitmapAlphaInfoMask; - + // Set noneSkipFirst. bitmapInfo |= kCGImageAlphaNoneSkipFirst; } @@ -245,7 +249,7 @@ - (UIImage *)decodedImageWithImage:(UIImage *)image { bitmapInfo &= ~kCGBitmapAlphaInfoMask; bitmapInfo |= kCGImageAlphaPremultipliedFirst; } - + // It calculates the bytes-per-row based on the bitsPerComponent and width arguments. CGContextRef context = CGBitmapContextCreate(NULL, imageSize.width, @@ -255,15 +259,15 @@ - (UIImage *)decodedImageWithImage:(UIImage *)image { colorSpace, bitmapInfo); CGColorSpaceRelease(colorSpace); - + // If failed, return undecompressed image if (!context) return image; - + CGContextDrawImage(context, imageRect, imageRef); CGImageRef decompressedImageRef = CGBitmapContextCreateImage(context); - + CGContextRelease(context); - + UIImage *decompressedImage = [UIImage imageWithCGImage:decompressedImageRef scale:image.scale orientation:image.imageOrientation]; CGImageRelease(decompressedImageRef); return decompressedImage; diff --git a/Classes/IDMTapDetectingImageView.h b/Classes/IDMTapDetectingImageView.h index 96a3865e..dfe11e42 100644 --- a/Classes/IDMTapDetectingImageView.h +++ b/Classes/IDMTapDetectingImageView.h @@ -7,10 +7,11 @@ // #import +#import @protocol IDMTapDetectingImageViewDelegate; -@interface IDMTapDetectingImageView : UIImageView { +@interface IDMTapDetectingImageView : YYAnimatedImageView { id __weak tapDelegate; } @property (nonatomic, weak) id tapDelegate; @@ -24,4 +25,4 @@ - (void)imageView:(UIImageView *)imageView singleTapDetected:(UITouch *)touch; - (void)imageView:(UIImageView *)imageView doubleTapDetected:(UITouch *)touch; - (void)imageView:(UIImageView *)imageView tripleTapDetected:(UITouch *)touch; -@end \ No newline at end of file +@end diff --git a/Demo/Podfile b/Demo/Podfile index cb335507..1d4a0f5b 100644 --- a/Demo/Podfile +++ b/Demo/Podfile @@ -5,7 +5,7 @@ inhibit_all_warnings! target "PhotoBrowserDemo" do -pod 'SDWebImage' +pod 'YYWebImage' pod 'DACircularProgress' pod 'pop' diff --git a/IDMPhotoBrowser.podspec b/IDMPhotoBrowser.podspec index b2e724f4..5a91c7f2 100644 --- a/IDMPhotoBrowser.podspec +++ b/IDMPhotoBrowser.podspec @@ -11,7 +11,7 @@ Pod::Spec.new do |s| s.resources = 'Classes/IDMPhotoBrowser.bundle', 'Classes/IDMPBLocalizations.bundle' s.framework = 'MessageUI', 'QuartzCore', 'SystemConfiguration', 'MobileCoreServices', 'Security' s.requires_arc = true - s.dependency 'SDWebImage' + s.dependency 'YYKit' s.dependency 'DACircularProgress' s.dependency 'pop' end From 15e16ddca94e2604c38e7914ef8862754029072a Mon Sep 17 00:00:00 2001 From: liangxuan Date: Wed, 20 Jun 2018 14:56:15 +0800 Subject: [PATCH 3/6] add git support add git support --- IDMPhotoBrowser.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IDMPhotoBrowser.podspec b/IDMPhotoBrowser.podspec index 5a91c7f2..6f0853f8 100644 --- a/IDMPhotoBrowser.podspec +++ b/IDMPhotoBrowser.podspec @@ -11,7 +11,7 @@ Pod::Spec.new do |s| s.resources = 'Classes/IDMPhotoBrowser.bundle', 'Classes/IDMPBLocalizations.bundle' s.framework = 'MessageUI', 'QuartzCore', 'SystemConfiguration', 'MobileCoreServices', 'Security' s.requires_arc = true - s.dependency 'YYKit' + s.dependency 'YYWebImage' s.dependency 'DACircularProgress' s.dependency 'pop' end From 25bb86361f2c1858f13a8dbe32b519c4c820eb5d Mon Sep 17 00:00:00 2001 From: rannger Date: Thu, 21 Jun 2018 18:28:39 +0800 Subject: [PATCH 4/6] fix --- IDMPhotoBrowser.podspec | 2 +- README.markdown | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/IDMPhotoBrowser.podspec b/IDMPhotoBrowser.podspec index 6f0853f8..5a91c7f2 100644 --- a/IDMPhotoBrowser.podspec +++ b/IDMPhotoBrowser.podspec @@ -11,7 +11,7 @@ Pod::Spec.new do |s| s.resources = 'Classes/IDMPhotoBrowser.bundle', 'Classes/IDMPBLocalizations.bundle' s.framework = 'MessageUI', 'QuartzCore', 'SystemConfiguration', 'MobileCoreServices', 'Security' s.requires_arc = true - s.dependency 'YYWebImage' + s.dependency 'YYKit' s.dependency 'DACircularProgress' s.dependency 'pop' end diff --git a/README.markdown b/README.markdown index 5549275a..c53b87b6 100644 --- a/README.markdown +++ b/README.markdown @@ -6,7 +6,7 @@ We've added both user experience and technical features inspired by Facebook's a ## New features: - Uses ARC -- Uses SDWebImage for image loading +- Uses YYWebImage for image loading - Image progress shown - Minimalistic Facebook-like interface, swipe up/down to dismiss - Ability to add custom actions on the action sheet @@ -181,7 +181,7 @@ Just add `pod 'IDMPhotoBrowser'` to your Podfile. #### Opensource libraries used -- [SDWebImage](https://github.com/rs/SDWebImage) +- [YYKit](https://github.com/ibireme/YYKit) - [DACircularProgress](https://github.com/danielamitay/DACircularProgress) - [pop](https://github.com/facebook/pop) From 87fe06aea2756d3dbb5629cf1d7e916630317adf Mon Sep 17 00:00:00 2001 From: rannger Date: Sat, 28 Jul 2018 13:51:31 +0800 Subject: [PATCH 5/6] fix --- IDMPhotoBrowser.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IDMPhotoBrowser.podspec b/IDMPhotoBrowser.podspec index 5a91c7f2..fb141f6c 100644 --- a/IDMPhotoBrowser.podspec +++ b/IDMPhotoBrowser.podspec @@ -11,7 +11,7 @@ Pod::Spec.new do |s| s.resources = 'Classes/IDMPhotoBrowser.bundle', 'Classes/IDMPBLocalizations.bundle' s.framework = 'MessageUI', 'QuartzCore', 'SystemConfiguration', 'MobileCoreServices', 'Security' s.requires_arc = true - s.dependency 'YYKit' + s.dependency 'YYKit', :git => 'https://github.com/rannger/YYKit.git' s.dependency 'DACircularProgress' s.dependency 'pop' end From 22e862dbc8bec68effc98b2b84a8f2f1cfbd4615 Mon Sep 17 00:00:00 2001 From: rannger Date: Sat, 28 Jul 2018 14:11:23 +0800 Subject: [PATCH 6/6] clean --- IDMPhotoBrowser.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IDMPhotoBrowser.podspec b/IDMPhotoBrowser.podspec index fb141f6c..c3042438 100644 --- a/IDMPhotoBrowser.podspec +++ b/IDMPhotoBrowser.podspec @@ -11,7 +11,7 @@ Pod::Spec.new do |s| s.resources = 'Classes/IDMPhotoBrowser.bundle', 'Classes/IDMPBLocalizations.bundle' s.framework = 'MessageUI', 'QuartzCore', 'SystemConfiguration', 'MobileCoreServices', 'Security' s.requires_arc = true - s.dependency 'YYKit', :git => 'https://github.com/rannger/YYKit.git' + s.dependency 'YYKit' s.dependency 'DACircularProgress' s.dependency 'pop' end