Merge pull request #2737 from kinarob/Fix_button_background_image_key_for_state_bug

Fix get button background image operation key bug
This commit is contained in:
DreamPiggy 2019-05-26 14:25:29 +08:00 committed by GitHub
commit 51fc2e8f83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 9 deletions

View File

@ -189,7 +189,7 @@ static inline NSString * backgroundImageOperationKeyForState(UIControlState stat
} else { } else {
mutableContext = [NSMutableDictionary dictionary]; mutableContext = [NSMutableDictionary dictionary];
} }
mutableContext[SDWebImageContextSetImageOperationKey] = imageOperationKeyForState(state); mutableContext[SDWebImageContextSetImageOperationKey] = backgroundImageOperationKeyForState(state);
@weakify(self); @weakify(self);
[self sd_internalSetImageWithURL:url [self sd_internalSetImageWithURL:url
placeholderImage:placeholder placeholderImage:placeholder

View File

@ -171,10 +171,9 @@
SDImageTintTransformer *transformer6 = [SDImageTintTransformer transformerWithColor:tintColor]; SDImageTintTransformer *transformer6 = [SDImageTintTransformer transformerWithColor:tintColor];
SDImageBlurTransformer *transformer7 = [SDImageBlurTransformer transformerWithRadius:blurRadius]; SDImageBlurTransformer *transformer7 = [SDImageBlurTransformer transformerWithRadius:blurRadius];
#if SD_UIKIT || SD_MAC
CIFilter *filter = [CIFilter filterWithName:@"CIColorInvert"]; CIFilter *filter = [CIFilter filterWithName:@"CIColorInvert"];
SDImageFilterTransformer *transformer8 = [SDImageFilterTransformer transformerWithFilter:filter]; SDImageFilterTransformer *transformer8 = [SDImageFilterTransformer transformerWithFilter:filter];
#endif
// Chain all built-in transformers for test case // Chain all built-in transformers for test case
SDImagePipelineTransformer *pipelineTransformer = [SDImagePipelineTransformer transformerWithTransformers:@[ SDImagePipelineTransformer *pipelineTransformer = [SDImagePipelineTransformer transformerWithTransformers:@[
transformer1, transformer1,
@ -184,9 +183,7 @@
transformer5, transformer5,
transformer6, transformer6,
transformer7, transformer7,
#if SD_UIKIT || SD_MAC transformer8
transformer8,
#endif
]]; ]];
NSArray *transformerKeys = @[ NSArray *transformerKeys = @[
@"SDImageResizingTransformer({100.000000,100.000000},2)", @"SDImageResizingTransformer({100.000000,100.000000},2)",
@ -196,9 +193,7 @@
@"SDImageCroppingTransformer({0.000000,0.000000,50.000000,50.000000})", @"SDImageCroppingTransformer({0.000000,0.000000,50.000000,50.000000})",
@"SDImageTintTransformer(#00000000)", @"SDImageTintTransformer(#00000000)",
@"SDImageBlurTransformer(5.000000)", @"SDImageBlurTransformer(5.000000)",
#if SD_UIKIT || SD_MAC @"SDImageFilterTransformer(CIColorInvert)"
@"SDImageFilterTransformer(CIColorInvert)",
#endif
]; ];
NSString *transformerKey = [transformerKeys componentsJoinedByString:@"-"]; // SDImageTransformerKeySeparator NSString *transformerKey = [transformerKeys componentsJoinedByString:@"-"]; // SDImageTransformerKeySeparator
expect([pipelineTransformer.transformerKey isEqualToString:transformerKey]).beTruthy(); expect([pipelineTransformer.transformerKey isEqualToString:transformerKey]).beTruthy();

View File

@ -120,6 +120,16 @@
}]; }];
[self waitForExpectationsWithCommonTimeout]; [self waitForExpectationsWithCommonTimeout];
} }
- (void)testUIButtonBackgroundImageCancelCurrentImageLoad {
UIButton *button = [[UIButton alloc] init];
NSURL *originalImageURL = [NSURL URLWithString:kTestJPEGURL];
[button sd_setBackgroundImageWithURL:originalImageURL forState:UIControlStateNormal];
[button sd_cancelBackgroundImageLoadForState:UIControlStateNormal];
NSString *backgroundImageOperationKey = [self testBackgroundImageOperationKeyForState:UIControlStateNormal];
expect([button sd_imageLoadOperationForKey:backgroundImageOperationKey]).beNil();
}
#endif #endif
#if SD_MAC #if SD_MAC
@ -339,4 +349,10 @@
return [testBundle pathForResource:@"TestImage" ofType:@"jpg"]; return [testBundle pathForResource:@"TestImage" ofType:@"jpg"];
} }
#if SD_UIKIT
- (NSString *)testBackgroundImageOperationKeyForState:(UIControlState)state {
return [NSString stringWithFormat:@"UIButtonBackgroundImageOperation%lu", (unsigned long)state];
}
#endif
@end @end