RCTImageURLLoader.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #import <UIKit/UIKit.h>
  8. #import <React/RCTBridge.h>
  9. #import <React/RCTResizeMode.h>
  10. typedef void (^RCTImageLoaderProgressBlock)(int64_t progress, int64_t total);
  11. typedef void (^RCTImageLoaderPartialLoadBlock)(UIImage *image);
  12. typedef void (^RCTImageLoaderCompletionBlock)(NSError *error, UIImage *image);
  13. typedef dispatch_block_t RCTImageLoaderCancellationBlock;
  14. /**
  15. * Provides the interface needed to register an image loader. Image data
  16. * loaders are also bridge modules, so should be registered using
  17. * RCT_EXPORT_MODULE().
  18. */
  19. @protocol RCTImageURLLoader <RCTBridgeModule>
  20. /**
  21. * Indicates whether this data loader is capable of processing the specified
  22. * request URL. Typically the handler would examine the scheme/protocol of the
  23. * URL to determine this.
  24. */
  25. - (BOOL)canLoadImageURL:(NSURL *)requestURL;
  26. /**
  27. * Send a network request to load the request URL. The method should call the
  28. * progressHandler (if applicable) and the completionHandler when the request
  29. * has finished. The method should also return a cancellation block, if
  30. * applicable.
  31. */
  32. - (nullable RCTImageLoaderCancellationBlock)loadImageForURL:(NSURL *)imageURL
  33. size:(CGSize)size
  34. scale:(CGFloat)scale
  35. resizeMode:(RCTResizeMode)resizeMode
  36. progressHandler:(RCTImageLoaderProgressBlock)progressHandler
  37. partialLoadHandler:(RCTImageLoaderPartialLoadBlock)partialLoadHandler
  38. completionHandler:(RCTImageLoaderCompletionBlock)completionHandler;
  39. @optional
  40. /**
  41. * If more than one RCTImageURLLoader responds YES to `-canLoadImageURL:`
  42. * then `loaderPriority` is used to determine which one to use. The loader
  43. * with the highest priority will be selected. Default priority is zero. If
  44. * two or more valid loaders have the same priority, the selection order is
  45. * undefined.
  46. */
  47. - (float)loaderPriority;
  48. /**
  49. * If the loader must be called on the serial url cache queue, and whether the completion
  50. * block should be dispatched off the main thread. If this is NO, the loader will be
  51. * called from the main queue. Defaults to YES.
  52. *
  53. * Use with care: disabling scheduling will reduce RCTImageLoader's ability to throttle
  54. * network requests.
  55. */
  56. - (BOOL)requiresScheduling;
  57. /**
  58. * If images loaded by the loader should be cached in the decoded image cache.
  59. * Defaults to YES.
  60. */
  61. - (BOOL)shouldCacheLoadedImages;
  62. @end