Skip to content

Commit 300ec4f

Browse files
committed
协议增加当前对应的数据模型
1 parent 268d8a4 commit 300ec4f

11 files changed

+48
-16
lines changed

GKPhotoBrowser/Core/Browser/GKPhotoBrowser.m

+6
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,9 @@ - (void)setupVideoPlayerProtocol:(id<GKVideoPlayerProtocol>)protocol {
404404
}
405405

406406
if ([self.progress respondsToSelector:@selector(updatePlayStatus:)]) {
407+
if ([self.progress respondsToSelector:@selector(setPhoto:)]) {
408+
self.progress.photo = self.curPhotoView.photo;
409+
}
407410
[self.progress updatePlayStatus:status];
408411
}
409412

@@ -509,6 +512,9 @@ - (void)updateCoverViews {
509512
self.progressView.hidden = YES;
510513
}
511514
if (self.cover && [self.cover respondsToSelector:@selector(updateCoverWithPhoto:)]) {
515+
if ([self.cover respondsToSelector:@selector(setPhoto:)]) {
516+
self.cover.photo = photo;
517+
}
512518
[self.cover updateCoverWithPhoto:photo];
513519
}
514520
}

GKPhotoBrowser/Core/Category/UIImage+GKPhotoBrowser.h

+2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ NS_ASSUME_NONNULL_BEGIN
1111

1212
@interface UIImage (GKPhotoBrowser)
1313

14+
/// 获取bundle图片
1415
+ (UIImage *)gkbrowser_imageNamed:(NSString *)name;
1516

17+
/// 获取gif图片
1618
+ (UIImage *)gkbrowser_imageWithData:(NSData *)data;
1719

1820
@end

GKPhotoBrowser/Core/PhotoView/GKPhoto.m

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ - (BOOL)isVideo {
2828
return !self.isLivePhoto && (self.videoUrl || self.videoAsset);
2929
}
3030

31+
- (BOOL)isLivePhoto {
32+
if (self.imageAsset) {
33+
return self.imageAsset.mediaSubtypes & PHAssetMediaSubtypePhotoLive;
34+
}
35+
return _isLivePhoto;
36+
}
37+
3138
- (void)getImage:(void (^)(NSData * _Nullable, UIImage * _Nullable, NSError * _Nullable))completion {
3239
if (!self.imageAsset) {
3340
NSError *error = [NSError errorWithDomain:@"com.browser.error" code:-1 userInfo:@{NSLocalizedDescriptionKey: @"没有图片资源"}];
@@ -99,13 +106,6 @@ - (void)getVideo:(void (^)(NSURL * _Nullable, NSError * _Nullable))completion {
99106
}
100107
}
101108

102-
- (BOOL)isLivePhoto {
103-
if (self.imageAsset) {
104-
return self.imageAsset.mediaSubtypes & PHAssetMediaSubtypePhotoLive;
105-
}
106-
return _isLivePhoto;
107-
}
108-
109109
#pragma mark - Private
110110
- (PHImageRequestID)loadImageDataWithAsset:(PHAsset *)asset completion:(void(^)(NSData *, NSError *))completion {
111111
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];

GKPhotoBrowser/Core/PhotoView/GKPhotoView+Image.m

+4-2
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ - (void)loadWebImageWithPhoto:(GKPhoto *)photo isOrigin:(BOOL)isOrigin placehold
234234
}
235235
});
236236
};
237+
238+
if ([self.imager respondsToSelector:@selector(setPhoto:)]) {
239+
self.imager.photo = photo;
240+
}
237241
[self.imager setImageForImageView:self.imageView url:url placeholderImage:placeholderImage progress:progressBlock completion:completionBlock];
238242
}else {
239243
if (self.imageView.image) {
@@ -342,8 +346,6 @@ - (void)adjustImageFrame {
342346
}
343347
}
344348

345-
346-
347349
self.loadingView.frame = self.bounds;
348350
self.videoLoadingView.frame = self.bounds;
349351
self.liveLoadingView.frame = self.bounds;

GKPhotoBrowser/Core/PhotoView/GKPhotoView+LivePhoto.m

+3
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ - (void)liveDidScrollAppear {
9696
if (!self.livePhoto.photo || self.livePhoto.photo != self.photo) {
9797
[self showLoading];
9898
__weak __typeof(self) weakSelf = self;
99+
if ([self.livePhoto respondsToSelector:@selector(setPhoto:)]) {
100+
self.livePhoto.photo = self.photo;
101+
}
99102
[self.livePhoto loadLivePhotoWithPhoto:self.photo targetSize:self.configure.liveTargetSize progressBlock:^(float progress) {
100103
__strong __typeof(weakSelf) self = weakSelf;
101104
dispatch_async(dispatch_get_main_queue(), ^{

GKPhotoBrowser/Core/PhotoView/GKPhotoView+Video.m

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ - (void)videoDidScrollAppear {
6969
// 如果没有设置,则设置播放内容
7070
if (!self.player.assetURL || self.player.assetURL != self.photo.videoUrl) {
7171
__weak __typeof(self) weakSelf = self;
72+
if ([self.player respondsToSelector:@selector(setPhoto:)]) {
73+
self.player.photo = self.photo;
74+
}
7275
[self.photo getVideo:^(NSURL * _Nullable url, NSError * _Nullable error) {
7376
__strong __typeof(weakSelf) self = weakSelf;
7477
if (!self) return;

GKPhotoBrowser/Core/Protocol/GKCoverViewProtocol.h

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121

2222
@optional
2323

24+
/// 当前对应的数据模型
25+
@property (nonatomic, weak, nullable) GKPhoto *photo;
26+
2427
/// 更新索引
2528
- (void)updateCoverWithCount:(NSInteger)count index:(NSInteger)index;
2629

GKPhotoBrowser/Core/Protocol/GKLivePhotoProtocol.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
#import <Photos/Photos.h>
1111
#import <PhotosUI/PhotosUI.h>
1212

13-
@class GKPhoto;
14-
@class GKPhotoBrowser;
13+
@class GKPhotoBrowser, GKPhoto;
1514

1615
typedef NS_ENUM(NSUInteger, GKLivePlayStatus) {
1716
GKLivePlayStatusBegin,
@@ -24,8 +23,6 @@ typedef NS_ENUM(NSUInteger, GKLivePlayStatus) {
2423

2524
@property (nonatomic, strong, nullable) PHLivePhotoView *livePhotoView;
2625

27-
@property (nonatomic, strong, nullable) GKPhoto *photo;
28-
2926
@property (nonatomic, assign) BOOL isPlaying;
3027

3128
@property (nonatomic, copy, nullable) void(^liveStatusChanged)(id<GKLivePhotoProtocol> _Nonnull mgr, GKLivePlayStatus status);
@@ -46,6 +43,10 @@ typedef NS_ENUM(NSUInteger, GKLivePlayStatus) {
4643
- (void)gk_setMute:(BOOL)mute;
4744

4845
@optional
46+
47+
/// 当前对应的数据模型
48+
@property (nonatomic, weak, nullable) GKPhoto *photo;
49+
4950
// 清除下载的文件
5051
- (void)gk_clear;
5152

GKPhotoBrowser/Core/Protocol/GKProgressViewProtocol.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
NS_ASSUME_NONNULL_BEGIN
1313

14-
@class GKPhotoBrowser;
14+
@class GKPhotoBrowser, GKPhoto;
1515

1616
@protocol GKProgressViewProtocol <NSObject>
1717

@@ -20,6 +20,10 @@ NS_ASSUME_NONNULL_BEGIN
2020
@property (nonatomic, strong, nullable) UIView *progressView;
2121

2222
@optional
23+
24+
// 当前对应的数据模型
25+
@property (nonatomic, weak, nullable) GKPhoto *photo;
26+
2327
// 更新状态
2428
- (void)updatePlayStatus:(GKVideoPlayerStatus)status;
2529

GKPhotoBrowser/Core/Protocol/GKVideoPlayerProtocol.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ typedef NS_ENUM(NSUInteger, GKVideoPlayerStatus) {
1919
GKVideoPlayerStatusFailed // 播放失败
2020
};
2121

22-
@class GKPhotoBrowser;
22+
@class GKPhotoBrowser, GKPhoto;
2323

2424
@protocol GKVideoPlayerProtocol <NSObject>
2525

@@ -71,6 +71,10 @@ typedef NS_ENUM(NSUInteger, GKVideoPlayerStatus) {
7171
// 静音
7272
- (void)gk_setMute:(BOOL)mute;
7373

74+
@optional
75+
/// 当前对应的数据模型
76+
@property (nonatomic, weak, nullable) GKPhoto *photo;
77+
7478
@end
7579

7680
NS_ASSUME_NONNULL_END

GKPhotoBrowser/Core/Protocol/GKWebImageProtocol.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ typedef void (^GKWebImageProgressBlock)(NSInteger receivedSize, NSInteger expect
1212

1313
typedef void (^GKWebImageCompletionBlock)(UIImage * _Nullable image, NSURL * _Nullable url, BOOL finished, NSError * _Nullable error);
1414

15-
@class GKPhotoBrowser;
15+
@class GKPhotoBrowser, GKPhoto;
1616

1717
@protocol GKWebImageProtocol<NSObject>
1818

@@ -42,6 +42,10 @@ typedef void (^GKWebImageCompletionBlock)(UIImage * _Nullable image, NSURL * _Nu
4242
- (UIImage *_Nullable)imageFromMemoryForURL:(nullable NSURL *)url;
4343

4444
@optional
45+
46+
/// 当前对应的数据模型
47+
@property (nonatomic, weak, nullable) GKPhoto *photo;
48+
4549
/// 可选实现,主要用于加载相册图片资源PHAsset
4650
/// 根据data获取image对象
4751
/// @param data 图片数据

0 commit comments

Comments
 (0)