diff --git a/Libraries/Image/RCTImageLoader.h b/Libraries/Image/RCTImageLoader.h index ca9f8bd9928..db660691353 100644 --- a/Libraries/Image/RCTImageLoader.h +++ b/Libraries/Image/RCTImageLoader.h @@ -15,8 +15,9 @@ #import #import #import +#import -@interface RCTImageLoader : NSObject +@interface RCTImageLoader : NSObject - (instancetype)init; - (instancetype)initWithRedirectDelegate:(id)redirectDelegate NS_DESIGNATED_INITIALIZER; - (instancetype)initWithRedirectDelegate:(id)redirectDelegate diff --git a/Libraries/Image/RCTImageLoader.mm b/Libraries/Image/RCTImageLoader.mm index 635f89d22de..300442d4402 100644 --- a/Libraries/Image/RCTImageLoader.mm +++ b/Libraries/Image/RCTImageLoader.mm @@ -819,6 +819,14 @@ static UIImage *RCTResizeImageIfNeeded(UIImage *image, return [[RCTImageURLLoaderRequest alloc] initWithRequestId:loaderRequest.requestId imageURL:imageURLRequest.URL cancellationBlock:cancellationBlock]; } +- (NSString *)loaderModuleNameForRequestUrl:(NSURL *)url { + id loadHandler = [self imageURLLoaderForURL:url]; + if ([loadHandler respondsToSelector:@selector(loaderModuleNameForRequestUrl:)]) { + return [(id)loadHandler loaderModuleNameForRequestUrl:url]; + } + return nil; +} + - (void)trackURLImageContentDidSetForRequest:(RCTImageURLLoaderRequest *)loaderRequest { if (!loaderRequest) { diff --git a/Libraries/Image/RCTImageLoaderInstrumentableProtocol.h b/Libraries/Image/RCTImageLoaderInstrumentableProtocol.h new file mode 100644 index 00000000000..a803aa58daa --- /dev/null +++ b/Libraries/Image/RCTImageLoaderInstrumentableProtocol.h @@ -0,0 +1,15 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +@protocol RCTImageLoaderInstrumentableProtocol + +/** +* Image instrumentation - get name of the image loader module +*/ +- (NSString *)loaderModuleNameForRequestUrl:(NSURL *)url; + +@end diff --git a/Libraries/Image/RCTImageLoaderWithAttributionProtocol.h b/Libraries/Image/RCTImageLoaderWithAttributionProtocol.h index a862667623c..4334d074c70 100644 --- a/Libraries/Image/RCTImageLoaderWithAttributionProtocol.h +++ b/Libraries/Image/RCTImageLoaderWithAttributionProtocol.h @@ -9,13 +9,14 @@ #import #import +#import RCT_EXTERN BOOL RCTImageLoadingInstrumentationEnabled(void); RCT_EXTERN BOOL RCTImageLoadingPerfInstrumentationEnabled(void); RCT_EXTERN void RCTEnableImageLoadingInstrumentation(BOOL enabled); RCT_EXTERN void RCTEnableImageLoadingPerfInstrumentation(BOOL enabled); -@protocol RCTImageLoaderWithAttributionProtocol +@protocol RCTImageLoaderWithAttributionProtocol // TODO (T61325135): Remove C++ checks #ifdef __cplusplus diff --git a/Libraries/Image/RCTImageURLLoaderWithAttribution.h b/Libraries/Image/RCTImageURLLoaderWithAttribution.h index e5e8ca84844..23d269bee33 100644 --- a/Libraries/Image/RCTImageURLLoaderWithAttribution.h +++ b/Libraries/Image/RCTImageURLLoaderWithAttribution.h @@ -7,6 +7,7 @@ #import #import +#import // TODO (T61325135): Remove C++ checks #ifdef __cplusplus @@ -38,7 +39,7 @@ struct ImageURLLoaderAttribution { * Same as the RCTImageURLLoader interface, but allows passing in optional `attribution` information. * This is useful for per-app logging and other instrumentation. */ -@protocol RCTImageURLLoaderWithAttribution +@protocol RCTImageURLLoaderWithAttribution // TODO (T61325135): Remove C++ checks #ifdef __cplusplus diff --git a/React/Fabric/Mounting/ComponentViews/Image/RCTImageComponentView.h b/React/Fabric/Mounting/ComponentViews/Image/RCTImageComponentView.h index c8db70c6b80..b8bede664a7 100644 --- a/React/Fabric/Mounting/ComponentViews/Image/RCTImageComponentView.h +++ b/React/Fabric/Mounting/ComponentViews/Image/RCTImageComponentView.h @@ -12,7 +12,10 @@ NS_ASSUME_NONNULL_BEGIN /** * UIView class for root component. */ -@interface RCTImageComponentView : RCTViewComponentView +@interface RCTImageComponentView : RCTViewComponentView { + @protected + UIImageView *_imageView; +} @end diff --git a/React/Fabric/Mounting/ComponentViews/Image/RCTImageComponentView.mm b/React/Fabric/Mounting/ComponentViews/Image/RCTImageComponentView.mm index 0de4b95a592..bfbf79e52a3 100644 --- a/React/Fabric/Mounting/ComponentViews/Image/RCTImageComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/Image/RCTImageComponentView.mm @@ -25,7 +25,6 @@ using namespace facebook::react; @end @implementation RCTImageComponentView { - UIImageView *_imageView; ImageShadowNode::ConcreteStateTeller _stateTeller; ImageResponseObserverCoordinator const *_coordinator; RCTImageResponseObserverProxy _imageResponseObserverProxy; diff --git a/ReactCommon/react/renderer/imagemanager/ImageRequest.h b/ReactCommon/react/renderer/imagemanager/ImageRequest.h index 9666b634cab..a77c1f76c79 100644 --- a/ReactCommon/react/renderer/imagemanager/ImageRequest.h +++ b/ReactCommon/react/renderer/imagemanager/ImageRequest.h @@ -51,6 +51,13 @@ class ImageRequest final { */ void setCancelationFunction(std::function cancelationFunction); + /* + * Returns the Image Source associated with the request. + */ + const ImageSource getImageSource() const { + return imageSource_; + } + /* * Returns stored observer coordinator as a shared pointer. * Retain this *or* `ImageRequest` to ensure a correct lifetime of the object. diff --git a/ReactCommon/react/renderer/imagemanager/platform/ios/RCTImageManager.mm b/ReactCommon/react/renderer/imagemanager/platform/ios/RCTImageManager.mm index eb2e6ff51b1..b016a264b8b 100644 --- a/ReactCommon/react/renderer/imagemanager/platform/ios/RCTImageManager.mm +++ b/ReactCommon/react/renderer/imagemanager/platform/ios/RCTImageManager.mm @@ -63,6 +63,12 @@ using namespace facebook::react; dispatch_async(_backgroundSerialQueue, ^{ NSURLRequest *request = NSURLRequestFromImageSource(imageSource); + BOOL hasModuleName = [self->_imageLoader respondsToSelector:@selector(loaderModuleNameForRequestUrl:)]; + NSString *moduleName = hasModuleName ? [self->_imageLoader loaderModuleNameForRequestUrl:request.URL] : nil; + std::string moduleCString = + std::string([moduleName UTF8String], [moduleName lengthOfBytesUsingEncoding:NSUTF8StringEncoding]); + telemetry->setLoaderModuleName(moduleCString); + auto completionBlock = ^(NSError *error, UIImage *image) { auto observerCoordinator = weakObserverCoordinator.lock(); if (!observerCoordinator) { diff --git a/packages/rn-tester/Podfile.lock b/packages/rn-tester/Podfile.lock index 1c441013b39..51a0dea2c3b 100644 --- a/packages/rn-tester/Podfile.lock +++ b/packages/rn-tester/Podfile.lock @@ -514,7 +514,7 @@ SPEC CHECKSUMS: React-perflogger: 1f668f3e4d1adef1fafb3b95e7d6cf922113fe31 React-RCTActionSheet: 51c43beeb74ef41189e87fe9823e53ebf6210359 React-RCTAnimation: 62f271148b71d0200773b4959e99a80f624182d4 - React-RCTBlob: b81d69c4dc7f7891a6a3ec969bba9b0a9801b062 + React-RCTBlob: e3e60611af4a077b3c0a3f74f49a2c4a9a298da3 React-RCTImage: 37646ebc761e9f68781867e9e802afdadd18a3dc React-RCTLinking: b5c261eb3befe7d5c62a4706ae904943e73f9c82 React-RCTNetwork: 2f6c4ba283c9c2ea768fecc6c681d3ab9448b5f5