PINRemoteImageCategoryManager.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. //
  2. // PINRemoteImageCategory.h
  3. // Pods
  4. //
  5. // Created by Garrett Moon on 11/4/14.
  6. //
  7. //
  8. #if PIN_TARGET_IOS
  9. #import <UIKit/UIKit.h>
  10. #elif PIN_TARGET_MAC
  11. #import <Cocoa/Cocoa.h>
  12. #endif
  13. #import "PINRemoteImageManager.h"
  14. @protocol PINRemoteImageCategory;
  15. /**
  16. PINRemoteImageCategoryManager is a class that handles subclassing image display classes. PINImage+PINRemoteImage, UIButton+PINRemoteImage, etc, all delegate their work to this class. If you'd like to create a category to display an image on a view, you should mimic one of the above categories.
  17. */
  18. @interface PINRemoteImageCategoryManager : NSObject
  19. + (void)setImageOnView:(nonnull id <PINRemoteImageCategory>)view
  20. fromURL:(nullable NSURL *)url;
  21. + (void)setImageOnView:(nonnull id <PINRemoteImageCategory>)view
  22. fromURL:(nullable NSURL *)url
  23. placeholderImage:(nullable PINImage *)placeholderImage;
  24. + (void)setImageOnView:(nonnull id <PINRemoteImageCategory>)view
  25. fromURL:(nullable NSURL *)url
  26. placeholderImage:(nullable PINImage *)placeholderImage
  27. completion:(nullable PINRemoteImageManagerImageCompletion)completion;
  28. + (void)setImageOnView:(nonnull id <PINRemoteImageCategory>)view
  29. fromURL:(nullable NSURL *)url
  30. completion:(nullable PINRemoteImageManagerImageCompletion)completion;
  31. + (void)setImageOnView:(nonnull id <PINRemoteImageCategory>)view
  32. fromURL:(nullable NSURL *)url
  33. processorKey:(nullable NSString *)processorKey
  34. processor:(nullable PINRemoteImageManagerImageProcessor)processor;
  35. + (void)setImageOnView:(nonnull id <PINRemoteImageCategory>)view
  36. fromURL:(nullable NSURL *)url
  37. placeholderImage:(nullable PINImage *)placeholderImage
  38. processorKey:(nullable NSString *)processorKey
  39. processor:(nullable PINRemoteImageManagerImageProcessor)processor;
  40. + (void)setImageOnView:(nonnull id <PINRemoteImageCategory>)view
  41. fromURL:(nullable NSURL *)url
  42. processorKey:(nullable NSString *)processorKey
  43. processor:(nullable PINRemoteImageManagerImageProcessor)processor
  44. completion:(nullable PINRemoteImageManagerImageCompletion)completion;
  45. + (void)setImageOnView:(nonnull id <PINRemoteImageCategory>)view
  46. fromURLs:(nullable NSArray <NSURL *> *)urls
  47. placeholderImage:(nullable PINImage *)placeholderImage
  48. processorKey:(nullable NSString *)processorKey
  49. processor:(nullable PINRemoteImageManagerImageProcessor)processor
  50. completion:(nullable PINRemoteImageManagerImageCompletion)completion;
  51. + (void)setImageOnView:(nonnull id <PINRemoteImageCategory>)view
  52. fromURLs:(nullable NSArray <NSURL *> *)urls;
  53. + (void)setImageOnView:(nonnull id <PINRemoteImageCategory>)view
  54. fromURLs:(nullable NSArray <NSURL *> *)urls
  55. placeholderImage:(nullable PINImage *)placeholderImage;
  56. + (void)setImageOnView:(nonnull id <PINRemoteImageCategory>)view
  57. fromURLs:(nullable NSArray <NSURL *> *)urls
  58. placeholderImage:(nullable PINImage *)placeholderImage
  59. completion:(nullable PINRemoteImageManagerImageCompletion)completion;
  60. + (void)cancelImageDownloadOnView:(nonnull id <PINRemoteImageCategory>)view;
  61. + (nullable NSUUID *)downloadImageOperationUUIDOnView:(nonnull id <PINRemoteImageCategory>)view;
  62. + (void)setDownloadImageOperationUUID:(nullable NSUUID *)downloadImageOperationUUID onView:(nonnull id <PINRemoteImageCategory>)view;
  63. + (BOOL)updateWithProgressOnView:(nonnull id <PINRemoteImageCategory>)view;
  64. + (void)setUpdateWithProgressOnView:(BOOL)updateWithProgress onView:(nonnull id <PINRemoteImageCategory>)view;
  65. @end
  66. /**
  67. Protocol to implement on UIView subclasses to support PINRemoteImage
  68. */
  69. @protocol PINRemoteImageCategory <NSObject>
  70. //Call manager
  71. /**
  72. Set the image from the given URL.
  73. @param url NSURL to fetch from.
  74. */
  75. - (void)pin_setImageFromURL:(nullable NSURL *)url;
  76. /**
  77. Set the image from the given URL and set placeholder image while image at URL is being retrieved.
  78. @param url NSURL to fetch from.
  79. @param placeholderImage PINImage to set on the view while the image at URL is being retrieved.
  80. */
  81. - (void)pin_setImageFromURL:(nullable NSURL *)url placeholderImage:(nullable PINImage *)placeholderImage;
  82. /**
  83. Set the image from the given URL and call completion when finished.
  84. @param url NSURL to fetch from.
  85. @param completion Called when url has been retrieved and set on view.
  86. */
  87. - (void)pin_setImageFromURL:(nullable NSURL *)url completion:(nullable PINRemoteImageManagerImageCompletion)completion;
  88. /**
  89. Set the image from the given URL, set placeholder while image at url is being retrieved and call completion when finished.
  90. @param url NSURL to fetch from.
  91. @param placeholderImage PINImage to set on the view while the image at URL is being retrieved.
  92. @param completion Called when url has been retrieved and set on view.
  93. */
  94. - (void)pin_setImageFromURL:(nullable NSURL *)url placeholderImage:(nullable PINImage *)placeholderImage completion:(nullable PINRemoteImageManagerImageCompletion)completion;
  95. /**
  96. Retrieve the image from the given URL, process it using the passed in processor block and set result on view.
  97. @param url NSURL to fetch from.
  98. @param processorKey NSString key to uniquely identify processor. Used in caching.
  99. @param processor PINRemoteImageManagerImageProcessor processor block which should return the processed image.
  100. */
  101. - (void)pin_setImageFromURL:(nullable NSURL *)url processorKey:(nullable NSString *)processorKey processor:(nullable PINRemoteImageManagerImageProcessor)processor;
  102. /**
  103. Set placeholder on view and retrieve the image from the given URL, process it using the passed in processor block and set result on view.
  104. @param url NSURL to fetch from.
  105. @param placeholderImage PINImage to set on the view while the image at URL is being retrieved.
  106. @param processorKey NSString key to uniquely identify processor. Used in caching.
  107. @param processor PINRemoteImageManagerImageProcessor processor block which should return the processed image.
  108. */
  109. - (void)pin_setImageFromURL:(nullable NSURL *)url placeholderImage:(nullable PINImage *)placeholderImage processorKey:(nullable NSString *)processorKey processor:(nullable PINRemoteImageManagerImageProcessor)processor;
  110. /**
  111. Retrieve the image from the given URL, process it using the passed in processor block and set result on view. Call completion after image has been fetched, processed and set on view.
  112. @param url NSURL to fetch from.
  113. @param processorKey NSString key to uniquely identify processor. Used in caching.
  114. @param processor PINRemoteImageManagerImageProcessor processor block which should return the processed image.
  115. @param completion Called when url has been retrieved and set on view.
  116. */
  117. - (void)pin_setImageFromURL:(nullable NSURL *)url processorKey:(nullable NSString *)processorKey processor:(nullable PINRemoteImageManagerImageProcessor)processor completion:(nullable PINRemoteImageManagerImageCompletion)completion;
  118. /**
  119. Set placeholder on view and retrieve the image from the given URL, process it using the passed in processor block and set result on view. Call completion after image has been fetched, processed and set on view.
  120. @param url NSURL to fetch from.
  121. @param placeholderImage PINImage to set on the view while the image at URL is being retrieved.
  122. @param processorKey NSString key to uniquely identify processor. Used in caching.
  123. @param processor PINRemoteImageManagerImageProcessor processor block which should return the processed image.
  124. @param completion Called when url has been retrieved and set on view.
  125. */
  126. - (void)pin_setImageFromURL:(nullable NSURL *)url placeholderImage:(nullable PINImage *)placeholderImage processorKey:(nullable NSString *)processorKey processor:(nullable PINRemoteImageManagerImageProcessor)processor completion:(nullable PINRemoteImageManagerImageCompletion)completion;
  127. /**
  128. Retrieve one of the images at the passed in URLs depending on previous network performance and set result on view.
  129. @param urls NSArray of NSURLs sorted in increasing quality
  130. */
  131. - (void)pin_setImageFromURLs:(nullable NSArray <NSURL *> *)urls;
  132. /**
  133. Set placeholder on view and retrieve one of the images at the passed in URLs depending on previous network performance and set result on view.
  134. @param urls NSArray of NSURLs sorted in increasing quality
  135. @param placeholderImage PINImage to set on the view while the image at URL is being retrieved.
  136. */
  137. - (void)pin_setImageFromURLs:(nullable NSArray <NSURL *> *)urls placeholderImage:(nullable PINImage *)placeholderImage;
  138. /**
  139. Set placeholder on view and retrieve one of the images at the passed in URLs depending on previous network performance and set result on view. Call completion after image has been fetched and set on view.
  140. @param urls NSArray of NSURLs sorted in increasing quality
  141. @param placeholderImage PINImage to set on the view while the image at URL is being retrieved.
  142. @param completion Called when url has been retrieved and set on view.
  143. */
  144. - (void)pin_setImageFromURLs:(nullable NSArray <NSURL *> *)urls placeholderImage:(nullable PINImage *)placeholderImage completion:(nullable PINRemoteImageManagerImageCompletion)completion;
  145. /**
  146. Cancels the image download. Guarantees that previous setImage calls will *not* have their results set on the image view after calling this (as opposed to PINRemoteImageManager which does not guarantee cancellation).
  147. */
  148. - (void)pin_cancelImageDownload;
  149. /**
  150. Returns the NSUUID associated with any PINRemoteImage task currently running on the view.
  151. @return NSUUID associated with any PINRemoteImage task currently running on the view.
  152. */
  153. - (nullable NSUUID *)pin_downloadImageOperationUUID;
  154. /**
  155. Set the current NSUUID associated with a PINRemoteImage task running on the view.
  156. @param downloadImageOperationUUID NSUUID associated with a PINRemoteImage task.
  157. */
  158. - (void)pin_setDownloadImageOperationUUID:(nullable NSUUID *)downloadImageOperationUUID;
  159. /**
  160. Whether the view should update with progress images (such as those provided by progressive JPEG images).
  161. @return BOOL value indicating whether the view should update with progress images
  162. */
  163. @property (nonatomic, assign) BOOL pin_updateWithProgress;
  164. //Handle
  165. - (void)pin_setPlaceholderWithImage:(nullable PINImage *)image;
  166. - (void)pin_updateUIWithRemoteImageManagerResult:(nonnull PINRemoteImageManagerResult *)result;
  167. - (void)pin_clearImages;
  168. - (BOOL)pin_ignoreGIFs;
  169. @optional
  170. - (PINRemoteImageManagerDownloadOptions)pin_defaultOptions;
  171. @end