WXImgLoaderProtocol.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. #import "WXModuleProtocol.h"
  20. #import "WXType.h"
  21. @protocol WXImageOperationProtocol <NSObject>
  22. - (void)cancel;
  23. @end
  24. typedef NS_ENUM(NSInteger, WXImageLoaderCacheType) {
  25. /**
  26. * The image wasn't available the imageLoad caches, but was downloaded from the web.
  27. */
  28. WXImageLoaderCacheTypeNone,
  29. /**
  30. * The image was obtained from the disk cache.
  31. */
  32. WXImageLoaderCacheTypeDisk,
  33. /**
  34. * The image was obtained from the memory cache.
  35. */
  36. WXImageLoaderCacheTypeMemory
  37. };
  38. @protocol WXImgLoaderProtocol <WXModuleProtocol>
  39. /**
  40. * @abstract Creates a image download handler with a given URL
  41. *
  42. * @param url The URL of the image to download
  43. *
  44. * @param imageFrame The frame of the image you want to set
  45. *
  46. * @param options : The options to be used for this download
  47. *
  48. * @param completedBlock : A block called once the download is completed.
  49. * image : the image which has been download to local.
  50. * error : the error which has happened in download.
  51. * finished : a Boolean value indicating whether download action has finished.
  52. */
  53. - (id<WXImageOperationProtocol>)downloadImageWithURL:(NSString *)url imageFrame:(CGRect)imageFrame userInfo:(NSDictionary *)options completed:(void(^)(UIImage *image, NSError *error, BOOL finished))completedBlock;
  54. @optional
  55. /**
  56. * @abstract Creates a image download handler with a given URL
  57. *
  58. * @param imageView UIImageView to display the image
  59. *
  60. * @param url The URL of the image to download
  61. *
  62. * @param placeholder The image to be set initially, until the image request finishes.
  63. *
  64. * @param options : The options to be used for download operation
  65. *
  66. * @param progressBlock : A block called while the download start
  67. *
  68. * @param completedBlock : A block called once the download is completed.
  69. * image : the image which has been download to local.
  70. * error : the error which has happened in download.
  71. * finished : a Boolean value indicating whether download action has finished.
  72. */
  73. - (void)setImageViewWithURL:(UIImageView*)imageView
  74. url:(NSURL *)url
  75. placeholderImage:(UIImage *)placeholder
  76. options:(NSDictionary*)options
  77. progress:(void(^)(NSInteger receivedSize, NSInteger expectedSize))progressBlock
  78. completed:(void(^)(UIImage *image, NSError *error, WXImageLoaderCacheType cacheType, NSURL *imageURL))completedBlock;
  79. /**
  80. * Cancel the current download image
  81. */
  82. - (void)cancelCurrentImageLoad:(UIImageView*)imageView;
  83. @end