RCTImageURLLoaderWithAttribution.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 <React/RCTImageURLLoader.h>
  8. #import <React/RCTImageLoaderProtocol.h>
  9. // TODO (T61325135): Remove C++ checks
  10. #ifdef __cplusplus
  11. namespace facebook {
  12. namespace react {
  13. struct ImageURLLoaderAttribution {
  14. int32_t nativeViewTag = 0;
  15. int32_t surfaceId = 0;
  16. };
  17. } // namespace react
  18. } // namespace facebook
  19. #endif
  20. @interface RCTImageURLLoaderRequest : NSObject
  21. @property (nonatomic, strong, readonly) NSString *requestId;
  22. @property (nonatomic, strong, readonly) NSURL *imageURL;
  23. @property (nonatomic, copy, readonly) RCTImageLoaderCancellationBlock cancellationBlock;
  24. - (instancetype)initWithRequestId:(NSString *)requestId imageURL:(NSURL *)imageURL cancellationBlock:(RCTImageLoaderCancellationBlock)cancellationBlock;
  25. - (void)cancel;
  26. @end
  27. /**
  28. * Same as the RCTImageURLLoader interface, but allows passing in optional `attribution` information.
  29. * This is useful for per-app logging and other instrumentation.
  30. */
  31. @protocol RCTImageURLLoaderWithAttribution <RCTImageURLLoader>
  32. // TODO (T61325135): Remove C++ checks
  33. #ifdef __cplusplus
  34. /**
  35. * Same as the RCTImageURLLoader variant above, but allows optional `attribution` information.
  36. * Caller may also specify a preferred requestId for tracking purpose.
  37. */
  38. - (RCTImageURLLoaderRequest *)loadImageForURL:(NSURL *)imageURL
  39. size:(CGSize)size
  40. scale:(CGFloat)scale
  41. resizeMode:(RCTResizeMode)resizeMode
  42. requestId:(NSString *)requestId
  43. priority: (RCTImageLoaderPriority)priority
  44. attribution:(const facebook::react::ImageURLLoaderAttribution &)attribution
  45. progressHandler:(RCTImageLoaderProgressBlock)progressHandler
  46. partialLoadHandler:(RCTImageLoaderPartialLoadBlock)partialLoadHandler
  47. completionHandler:(RCTImageLoaderCompletionBlock)completionHandler;
  48. #endif
  49. /**
  50. * Image instrumentation - notify that the image content (UIImage) has been set on the native view.
  51. */
  52. - (void)trackURLImageContentDidSetForRequest:(RCTImageURLLoaderRequest *)loaderRequest;
  53. /**
  54. * Image instrumentation - start tracking the on-screen visibility of the native image view.
  55. */
  56. - (void)trackURLImageVisibilityForRequest:(RCTImageURLLoaderRequest *)loaderRequest imageView:(UIView *)imageView;
  57. /**
  58. * Image instrumentation - notify that the native image view was destroyed.
  59. */
  60. - (void)trackURLImageDidDestroy:(RCTImageURLLoaderRequest *)loaderRequest;
  61. @end