3/6 Add IGviewpoint for image visibility callbacks

Summary: Changelog: [Internal] Add IGviewpoint to get image visibility callbacks for when an UIImageView is in or out of view

Reviewed By: fkgozali

Differential Revision: D23428528

fbshipit-source-id: 87e4cee8fbe3c6b7da5153f87bbb530b2f990d96
This commit is contained in:
Paige Sun
2020-09-11 15:09:12 -07:00
committed by Facebook GitHub Bot
parent d4e1202b4e
commit 13759f192d
10 changed files with 47 additions and 6 deletions
+2 -1
View File
@@ -15,8 +15,9 @@
#import <React/RCTImageURLLoader.h>
#import <React/RCTImageCache.h>
#import <React/RCTImageLoaderProtocol.h>
#import <React/RCTImageLoaderInstrumentableProtocol.h>
@interface RCTImageLoader : NSObject <RCTBridgeModule, RCTImageLoaderProtocol>
@interface RCTImageLoader : NSObject <RCTBridgeModule, RCTImageLoaderProtocol, RCTImageLoaderInstrumentableProtocol>
- (instancetype)init;
- (instancetype)initWithRedirectDelegate:(id<RCTImageRedirectProtocol>)redirectDelegate NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithRedirectDelegate:(id<RCTImageRedirectProtocol>)redirectDelegate
+8
View File
@@ -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<RCTImageURLLoader> loadHandler = [self imageURLLoaderForURL:url];
if ([loadHandler respondsToSelector:@selector(loaderModuleNameForRequestUrl:)]) {
return [(id<RCTImageURLLoaderWithAttribution>)loadHandler loaderModuleNameForRequestUrl:url];
}
return nil;
}
- (void)trackURLImageContentDidSetForRequest:(RCTImageURLLoaderRequest *)loaderRequest
{
if (!loaderRequest) {
@@ -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
@@ -9,13 +9,14 @@
#import <React/RCTImageLoaderProtocol.h>
#import <React/RCTImageURLLoaderWithAttribution.h>
#import <React/RCTImageLoaderInstrumentableProtocol.h>
RCT_EXTERN BOOL RCTImageLoadingInstrumentationEnabled(void);
RCT_EXTERN BOOL RCTImageLoadingPerfInstrumentationEnabled(void);
RCT_EXTERN void RCTEnableImageLoadingInstrumentation(BOOL enabled);
RCT_EXTERN void RCTEnableImageLoadingPerfInstrumentation(BOOL enabled);
@protocol RCTImageLoaderWithAttributionProtocol<RCTImageLoaderProtocol>
@protocol RCTImageLoaderWithAttributionProtocol<RCTImageLoaderProtocol, RCTImageLoaderInstrumentableProtocol>
// TODO (T61325135): Remove C++ checks
#ifdef __cplusplus
@@ -7,6 +7,7 @@
#import <React/RCTImageURLLoader.h>
#import <React/RCTImageLoaderProtocol.h>
#import <React/RCTImageLoaderInstrumentableProtocol.h>
// 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 <RCTImageURLLoader>
@protocol RCTImageURLLoaderWithAttribution <RCTImageURLLoader, RCTImageLoaderInstrumentableProtocol>
// TODO (T61325135): Remove C++ checks
#ifdef __cplusplus
@@ -12,7 +12,10 @@ NS_ASSUME_NONNULL_BEGIN
/**
* UIView class for root <Image> component.
*/
@interface RCTImageComponentView : RCTViewComponentView
@interface RCTImageComponentView : RCTViewComponentView {
@protected
UIImageView *_imageView;
}
@end
@@ -25,7 +25,6 @@ using namespace facebook::react;
@end
@implementation RCTImageComponentView {
UIImageView *_imageView;
ImageShadowNode::ConcreteStateTeller _stateTeller;
ImageResponseObserverCoordinator const *_coordinator;
RCTImageResponseObserverProxy _imageResponseObserverProxy;
@@ -51,6 +51,13 @@ class ImageRequest final {
*/
void setCancelationFunction(std::function<void(void)> 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.
@@ -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) {
+1 -1
View File
@@ -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