Skip to content
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 Request: Supports to specify the options in both per-image-request level as well as global control level #2719

Closed
3 tasks done
dreampiggy opened this issue May 8, 2019 · 2 comments

Comments

@dreampiggy
Copy link
Contributor

dreampiggy commented May 8, 2019

New Issue Checklist

Issue Info

Info Value
Platform Name All
Platform Version All
SDWebImage Version 5.0.2
Integration Method All
Xcode Version Xcode 10
Repro rate all the time (100%)

Feature Request

SDWebImage have two control options to load the image:

  • SDWebImageOption (options)
    A option mask to provide a BOOL-like option for each option. For example, [.avoidDecodeImage] to avoid force-decode the image.

  • SDWebImageContext (context)
    A dictionry to provide a K-V option for type beyond a bool value. For example, [.ImageScaleFactor : 2] to treate current image scale factor to be 2.

However, there are some users, who want to have a global control for some options.
#2283 the user, want a global control for the Force-Decoding feature, where some user from #1927 want a per-image-request level control

#2679 the user, want a global control to disable the Animation GIF on normal UIImageView, where some user still need this to place GIF on UIButton.imageView #2192

I understand that why our user facing this issue, because of that codebase rely on SDWebImage's View Category API can be seperated in different code unit. For example, if you dependency on a SDK about UI and images, or if you have a large project with separated business Pods, you may want a global control.

So, all this type of problem, can be concluded into one feature request:

User want to have both the global control (maybe in Manager level), but as well as the per-image-request level (the View Category method arg of options and context)

@dreampiggy
Copy link
Contributor Author

dreampiggy commented May 8, 2019

Solution

There are many solutions for achieving this feature, I can list some of them. But which one to do need further investigation and analysis.

Allows global control to override

We can use a global control, which override your SDWebImageOption. However, this is a problem: How can we override ?

This enum can only represent two meaning: YES (use force decoding) or NO (do not use). It can not represent this meanning: default (use the global control instead). Consider this code:

SDWebImageManager.sharedManager.avoidDecodeImage = NO;
[imageView sd_setImageWithURL:url option:SDWebImageAvoidDecodeImage];
// What's the final result for this option ?

One way for this, it to use the 5.0 new context option, which use a 3-case enum, or can use @(YES) for YES, @(NO) for NO, and nil for default.

This may cause API breaking, in my opinion. Or we need to deprecate the old option SDWebImageAvoidDecodeImage to use new context option like SDWebImageContextForceDecodeImage instead.

Add a default options feature

We can introduce a feature called default options, which will append the default option to final SDWebImageOptions.

This can also fix other related option where user want to take both global control && per-image-request control like SDWebImageDecodeFirstFrameOnly.

But actually, this feature have one disadvantage, how to solve the problem when some image request don't want the default option, but others want ?

SDWebImageManager.sharedManager.defaultOptions = SDWebImageAvoidDecodeImage;
[imageView sd_setImageWithURL:url option:0]; // How to do if I really want this image request, to trun the force decode on?
// Maybe something like this ?
[imageView sd_setImageWithURL:url option:SDWebImageIgnoreDefaultOptions]; // Ignore default options appending, final options result to 0

@stale
Copy link

stale bot commented Jun 20, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Issue List
  
Done
Development

No branches or pull requests

1 participant