New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature custom image loader - Supports loader protocol #2256
Conversation
SDWebImage/SDWebImageDefine.h
Outdated
@@ -12,6 +12,113 @@ typedef void(^SDWebImageNoParamsBlock)(void); | |||
typedef NSString * SDWebImageContextOption NS_STRING_ENUM; | |||
typedef NSDictionary<SDWebImageContextOption, id> SDWebImageContext; | |||
|
|||
typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just code moving :)
Because that SDWebImageLoader
protocol should not import SDWebImageDownloader
, or it will cause a cycle import issue.
I can seperate this into another PR after some 5.x feature merged to avoid future merge conflict. Not a big change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already been done in current 5.x branch.
SDWebImage/SDWebImageDownloader.m
Outdated
@@ -192,6 +192,37 @@ - (void)setOperationClass:(nullable Class)operationClass { | |||
} | |||
} | |||
|
|||
- (id<SDWebImageOperation>)loadImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageLoaderProgressBlock)progressBlock completed:(SDWebImageLoaderCompletedBlock)completedBlock context:(SDWebImageContext *)context { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code moving as well. Actually the SDWebImageDownloader
's basic logic does not change at all.
Current break change (Need change code)SDWebImageManager.h
|
SDWebImage/SDWebImagePhotosLoader.m
Outdated
return nil; | ||
} | ||
|
||
if (![[self class] isPhotosStatusAuthorized]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe when Photos Library no authorized, we should through a exception ? Or does this authorization check impact the performance ? I will check later. (Currently will check each time you request Photos asset)
SDWebImage/SDWebImageManager.m
Outdated
} | ||
if (!error) { | ||
dispatch_async(strongSubOperation.coderQueue, ^{ | ||
UIImage *loadedImage = [[SDWebImageCodersManager sharedManager] decodedImageWithData:data]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Acutally, here is not finished because we supports progressive image loading.
One solution, it's to leave this for other developer to use the loadImageWithURL:
one and build their own. Or I can continue to implement it to allow loadImageDataWithURL:
progressive loading. (Actually, copy
the code in SDWebImageDownloadOperation
. Or maybe a better way to share the code ?).
0f58946
to
fa45269
Compare
These are a lot of changes. I think the priority of the Photos support is not high. Maybe we should hold this PR until other PRs are merged. |
@skyline75489 :) Most changes is because of some unnessary changes from the early days of 5.x. I can rebase it to the 5.x after that #2278 merged. There should be only less than 10 files get effected. And because of that |
fa45269
to
51fa2fb
Compare
@skyline75489 Done...I just remove all the unnecessary changes, only keep the basic design for custom loader protocol. The Photos Library loader implementation can be create into another PR. I just keep in my temp branch to wait for this been merged. |
Some tests are failing |
This because I change that our complicated decoding logic, from However, I can't done this to pass the test, because I need to wait for #2283 . That global method does not pass a extra And also, this can be polished to wait for #2280, which can be used to generate the correct So, currently just ignore this PR. I'll polish this after some dependent PR merged 😅 |
94e6f27
to
6832284
Compare
A question. Am I considered too much to introduce two protocol methods for custom image loader ? typedef void(^SDWebImageLoaderCompletedBlock)(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished);
typedef void(^SDWebImageLoaderDataCompletedBlock)(NSData * _Nullable data, NSError * _Nullable error, BOOL finished);
Previously I think the second one is useful to integrate for some common However, after some consideration, since we can abstract the common logic for image decoding like that Maybe just leave the first one is enough ? (Actually the first one which need |
84bca88
to
5baeae7
Compare
SDWebImage/SDWebImageManager.m
Outdated
@@ -253,12 +245,6 @@ - (SDWebImageCombinedOperation *)loadImageWithURL:(nullable NSURL *)url | |||
} | |||
|
|||
BOOL cacheOnDisk = !(options & SDWebImageCacheMemoryOnly); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be refactored using the custom cache key filter feature. So we pass the cache key filter in context
for downloader, downloader use that to calculate cache key (or string from URL). We do not need this hack logic.
@dreampiggy i like the idea of |
@mythodeia @skyline75489 @bpoplauschi For that Photos framework loader, I create a demo CocoaPods and move the code there. You can see that about the way to write a custom image loader. Project: Just PS: Actually...This is just a test demo and I'm not satisfied with the naming (naming a |
db526ab
to
dc98660
Compare
294f841
to
5159f8c
Compare
Done Solving conflict and will rebase to small commits...Wait :) |
…ce the `SDWebImageLoadersManager` to manage multiple loaders with priority
5159f8c
to
23dcaf6
Compare
… image downloader description to loader
23dcaf6
to
d507442
Compare
Looking good @dreampiggy. I will go ahead and merge it. |
@dreampiggy regarding SDWebImage-Photos, I would recommend we move it under github.com/SDWebImage/ so all those extension projects are there. I would also rename it to |
@bpoplauschi Correct. I create it just for a demo and show for you. And I find that naming is wired if you add Maybe we'd better naming it like And also, it seems we should also create a |
I think |
➜ GitHub git:(master) ✗ pod lib create SDWebImage+PhotosFramework
[!] The Pod name cannot contain plusses.
Usage:
$ pod lib create NAME
Creates a scaffold for the development of a new Pod named `NAME` according to
the CocoaPods best practices. If a `TEMPLATE_URL`, pointing to a git repo
containing a compatible template, is specified, it will be used in place of the
default one.
Options:
--template-url=URL The URL of the git repo containing a compatible template
--silent Show nothing
--verbose Show more debugging information
--no-ansi Show output without ANSI codes
--help Show help banner of specified command And here is the code showing the reason: CocoaPods/CocoaPods The reason may belong to the issue that the build script will parse the path wrong if you have |
I see. Thanks for the details. CamelCase is ok, but not that readable. Anyway, we can go with CamelCase. |
@dreampiggy I'm updating the diagrams for the 5.0.0 release and I can't figure out what the |
@bpoplauschi The For example, you want to support both Network image URL, file path URL, as well as Photos URL for As compatible reason (See that |
@dreampiggy I see, they can be used via |
I must say this is not too intuitive :) |
New Pull Request Checklist
I have read and understood the CONTRIBUTING guide
I have read the Documentation
I have searched for a similar pull request in the project and found none
I have updated this branch with the latest master to avoid conflicts (via merge from master or rebase)
I have added the required tests to prove the fix/feature I am adding
I have updated the documentation (if necessary)
I have run the tests and they pass
I have run the lint and it passes (
pod lib lint
)This merge request fixes / reffers to the following issues: #1970 #906 #1702 #697
Pull Request Description
Reason
Though our project
SDWebImage
's fundamental function is to load the image from network, cache and render in the views. Things become more and more complicated and many user may have different use caseFor example, some user may use third-party cloud service such as FireBase, which provide their SDKs to retrive the image or data, so they can not be communicated with SDWebImage's total function easily without hacking. Many user also wants to load the file URL, Photos library as well, which may be a really helpful feature for beginning user. Since we can change things in 5.x, maybe we can make a more abstract layer to allow user to provide their own implementation of image loading system. But also keep the current downloader function with minimal change.
Design
For common image loading system, we can seperate them into two type.
The first one, a image loader will handler all the stuff, including
image data
retrieving (From network, or local files, whatever) and also the image processing. They can produce all the informationwe need for the final completion block we need forSDWebImageManager
. Which means they should provideNSData
+UIImage
. This is useful for Photos library loader which may use requestImageForAsset, which thedata
may be nil but theUIImage
instance is valid (This can work well with our cache system).The second one, a image loader may just concentrate on the
image data
retrieving, and don't care about image processing stuff. We can apply the common image decoding logic from SDWebImage itself to allow same behavior acrossing the coder. Which means they should provideNSData
only. This is useful for local file loader, which just need to get the image data.So, we can design a protocol which allow these two types of image loading process. This apply a abstract layer to let user provide their own image loader. And we can build a image load manager like
SDWebImageCodersManager
to allow multiple loaders at the same time. For our currentSDWebImageDownloader
, it should now also conform this protocol.Implementation
SDWebImageLoader Protocol
Loders Manager