Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upFeature request: Allows the UIButton to check and set different state for current `progress` and `transition` #2701
Comments
|
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. |
|
@cntrump Hi. I see you have some use case for this State-like View API. Which means, a Could you explain your detail use case, to help me to solve this issue, with a more general, extensible solution ? |
|
I wonder, if the user who want to call For example, if this is true, I'll provide some powerful API (but hard to use for simple one line code) for this. This is my first design draft. |
/**
A loading storage keeping all of the related property, associated to single image request
*/
@interface SDWebImageLoadStorage
// Description is same as current property
@property (nonatomic, strong, readonly, nullable) NSURL *imageURL;
@property (nonatomic, strong, null_resettable) NSProgress *imageProgress;
@property (nonatomic, strong, nullable) SDWebImageTransition *imageTransition;
@property (nonatomic, strong, nullable) id<SDWebImageIndicator> imageIndicator;
@end
@interface UIView (WebCache)
/**
Return the loading storage for specify operation key.
*/
- (nullable SDWebImageLoadStorage *)sd_imageLoadStorageForKey:(nullable NSString *)key;
/**
Specify a desired loading storage for opeartion key.
*/
- (void)sd_setImageLoadStorage:(nullable SDWebImageLoadStorage *)storage forKey:(nullable NSString *)key;
@end |
|
Usage code for cases when I want to observe different state's loading progress on UIButton: - (void)testUIButton {
NSURL *url;
NSURL *disabledUrl;
// Normal
SDWebImageLoadStorage *storage = [SDWebImageLoadStorage new];
UIButton *button = [UIButton new];
UIControlState state = UIControlStateNormal;
NSString *key = [UIButton sd_imageOperationKeyForState:state];
[button sd_setImageLoadStorage:storage forKey:key];
[self.KVOController observe:storage.imageProgress keyPath:NSStringFromSelector(@selector(fractionCompleted)) options:NSKeyValueObservingOptionNew block:^(id _Nullable observer, id _Nonnull object, NSDictionary<NSString *,id> * _Nonnull change) {
// ....
}];
[button sd_setImageWithURL:url forState:state];
// Disabled
state = UIControlStateDisabled;
key = [UIButton sd_imageOperationKeyForState:state];
SDWebImageLoadStorage *disabledStorage = [SDWebImageLoadStorage new];
[button sd_setImageLoadStorage:disabledStorage forKey:key];
[self.KVOController observe:disabledStorage.imageProgress keyPath:NSStringFromSelector(@selector(fractionCompleted)) options:NSKeyValueObservingOptionNew block:^(id _Nullable observer, id _Nonnull object, NSDictionary<NSString *,id> * _Nonnull change) {
// ....
}];
[button sd_setImageWithURL:disabledUrl forState:state];
} |
|
Usage code for cases when I want to set different transaction animation for normal image and highlighted image on UIImageView: - (void)testUIImageView {
NSURL *url;
NSURL *highlightedUrl;
// image
UIImageView *imageView = [UIImageView new];
SDWebImageLoadStorage *storage = [SDWebImageLoadStorage new];
storage.imageTransition = SDWebImageTransition.fadeTransition;
NSString *key = [UIImageView sd_imageOperationKey]; // actually is nil, or `NSStringFromClass`
[imageView sd_setImageLoadStorage:storage forKey:key];
[imageView sd_setImageWithURL:url];
// highlighted image
key = [UIImageView sd_highlightedImageOperationKey];
SDWebImageLoadStorage *backgroundStorage = [SDWebImageLoadStorage new];
backgroundStorage.imageTransition = SDWebImageTransition.flipFromTopTransition;
[imageView sd_setHighlightedImageWithURL:highlightedUrl];
} |
|
Those @interface UIButton (WebCache)
/**
Get the image progress for a control state.
*/
- (nullable NSProgress *)sd_imageProgressForState:(UIControlState)state;
/**
Get the background image progress for a control state.
*/
- (nullable NSProgress *)sd_backgroundImageProgressForState:(UIControlState)state;
@end
@implementation UIButton (WebCache)
- (NSProgress *)sd_imageProgressForState:(UIControlState)state {
NSString *key = [UIButton sd_imageOperationKeyForState:state];
SDWebImageLoadStorage *storage = [self sd_imageLoadStorageForKey:key];
return storage.imageProgress;
}
- (NSProgress *)sd_backgroundImageProgressForState:(UIControlState)state {
NSString *key = [UIButton sd_backgroundImageOperationKeyForState:state];
SDWebImageLoadStorage *storage = [self sd_imageLoadStorageForKey:key];
return storage.imageProgress;
}
@end |
|
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. |
|
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. |
|
Fix in future |
|
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. |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

New Issue Checklist
Feature Description
SDWebImage's
UIView+WebCache, provide some properties, likeIt works great for normal UIImageView, which have one single image to be query and load.
However, things become more complicated when using these properties on
UIButton, because UIButton have different state, each state can represent a different image query pipelilne. See the already exist API:So, actually, these properties, which tied to single image request, should also have a correspond API for different UIButton state. Like the following:
Similar use case
The same thing, can also apply for the
UIImageView+HighlightedWebCache, which should have the coorespond APIs like the following:Note: The Indicator feature, is not under consideration for this case, because from all the usage, the indicator on
UIButtonis not a good idea. And it's a UIView's subview, it's not designed to dynamically removed and re-add base on state.