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

Haneke doesn't resize images in background? #113

Open
mixtly87 opened this issue Nov 6, 2017 · 0 comments
Open

Haneke doesn't resize images in background? #113

mixtly87 opened this issue Nov 6, 2017 · 0 comments

Comments

@mixtly87
Copy link

mixtly87 commented Nov 6, 2017

Am I missing something or Haneke actually does NOT resize network-retrieved images on the background, but performs the resizing on the main thread.

I noticed my scroll performance on UITableView stutters and profiling led to hnk_imageByScalingToSize being called on main thread.

I ended up adding dispatch_async to - (BOOL)fetchImageForFetcher:formatName:success:failure:

- (BOOL)fetchImageForFetcher:(id<HNKFetcher>)fetcher formatName:(NSString *)formatName success:(void (^)(UIImage *image))successBlock failure:(void (^)(NSError *error))failureBlock
{
    NSString *key = fetcher.key;
    return [self fetchImageForKey:key formatName:formatName success:^(UIImage *image) {
        if (successBlock) successBlock(image);
    } failure:^(NSError *error) {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            HNKCacheFormat *format = _formats[formatName];

            [self fetchImageFromFetcher:fetcher completionBlock:^(UIImage *originalImage, NSError *error) {
                if (!originalImage)
                {
                    dispatch_async(dispatch_get_main_queue(), ^{
                        if (failureBlock) failureBlock(error);
                    });
                    return;
                }

                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                    UIImage* image = [self imageFromOriginal:originalImage key:key format:format];
                    [self setDiskImage:image forKey:key format:format];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [self setMemoryImage:image forKey:key format:format];
                        if (successBlock)
                        {successBlock(image);}
                    });
                });
            }];
        });
    }];
}

I'm not sure if this is a no-no for any reason. I was surprised to see that images are resized on the main queue, when one of the stated features is 'Background image resizing and file reading.'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant