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

fix(ios): Image capInsets bug #3620

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading