Skip to content

Commit

Permalink
fix(ios): Image capInsets bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwcg committed Nov 17, 2023
1 parent e7b8241 commit 092db23
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
15 changes: 12 additions & 3 deletions modules/ios/image/HippyDefaultImageProvider.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ @interface HippyDefaultImageProvider () {

@implementation HippyDefaultImageProvider

@synthesize imageDataPath;
@synthesize scale = _scale;
@synthesize imageDataPath = _imageDataPath;

+ (BOOL)canHandleData:(NSData *)data {
return YES;
Expand All @@ -46,6 +47,14 @@ + (BOOL)isAnimatedImage:(NSData *)data {
return ret;
}

- (instancetype)init {
self = [super init];
if (self) {
_scale = 1.0;
}
return self;
}

- (void)setImageData:(NSData *)imageData {
if ([[self class] isAnimatedImage:imageData]) {
_imageSourceRef = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL);
Expand All @@ -55,12 +64,12 @@ - (void)setImageData:(NSData *)imageData {
}

- (UIImage *)image {
CGFloat scale = [UIScreen mainScreen].scale;
if (!_image) {
if (_data) {
CGFloat view_width = _imageViewSize.width;
CGFloat view_height = _imageViewSize.height;
if (_downSample && view_width > 0 && view_height > 0) {
CGFloat scale = self.scale;
NSDictionary *options = @{ (NSString *)kCGImageSourceShouldCache: @(NO) };
CGImageSourceRef ref = CGImageSourceCreateWithData((__bridge CFDataRef)_data, (__bridge CFDictionaryRef)options);
if (ref) {
Expand Down Expand Up @@ -95,7 +104,7 @@ - (UIImage *)image {
}
}
if (!_image) {
_image = [UIImage imageWithData:_data scale:scale];
_image = [UIImage imageWithData:_data scale:self.scale];
}
return _image;
}
Expand Down
5 changes: 5 additions & 0 deletions modules/ios/image/HippyImageProviderProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@

@property(nonatomic, copy)NSString *imageDataPath;

/**
* Image scale
*/
@property (nonatomic, assign) CGFloat scale;

/**
* Set image data for provider
*
Expand Down

0 comments on commit 092db23

Please sign in to comment.