Skip to content

Commit

Permalink
Annotate <Image> components in QPL logging using ImageAnalyticsTagCon…
Browse files Browse the repository at this point in the history
…text

Reviewed By: mdvacca

Differential Revision: D21696266

fbshipit-source-id: b5c9d167e9da77ed969f7b4bdea1af9dd2e471ae
  • Loading branch information
p-sun authored and facebook-github-bot committed May 24, 2020
1 parent 1b1ebaf commit 60b7a30
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 8 deletions.
24 changes: 16 additions & 8 deletions Libraries/Image/Image.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const React = require('react');
const ReactNative = require('../Renderer/shims/ReactNative'); // eslint-disable-line no-unused-vars
const StyleSheet = require('../StyleSheet/StyleSheet');

const ImageAnalyticsTagContext = require('./ImageAnalyticsTagContext').default;
const flattenStyle = require('../StyleSheet/flattenStyle');
const resolveAssetSource = require('./resolveAssetSource');

Expand Down Expand Up @@ -124,14 +125,21 @@ let Image = (props: ImagePropsType, forwardedRef) => {
}

return (
<ImageViewNativeComponent
{...props}
ref={forwardedRef}
style={style}
resizeMode={resizeMode}
tintColor={tintColor}
source={sources}
/>
<ImageAnalyticsTagContext.Consumer>
{analyticTag => {
return (
<ImageViewNativeComponent
{...props}
ref={forwardedRef}
style={style}
resizeMode={resizeMode}
tintColor={tintColor}
source={sources}
internal_analyticTag={analyticTag}
/>
);
}}
</ImageAnalyticsTagContext.Consumer>
);
};

Expand Down
1 change: 1 addition & 0 deletions Libraries/Image/RCTImageURLLoaderWithAttribution.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace react {
struct ImageURLLoaderAttribution {
int32_t nativeViewTag = 0;
int32_t surfaceId = 0;
NSString *analyticTag;
};

} // namespace react
Expand Down
1 change: 1 addition & 0 deletions Libraries/Image/RCTImageView.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
@property (nonatomic, copy) NSArray<RCTImageSource *> *imageSources;
@property (nonatomic, assign) CGFloat blurRadius;
@property (nonatomic, assign) RCTResizeMode resizeMode;
@property (nonatomic, copy) NSString *internal_analyticTag;

@end
8 changes: 8 additions & 0 deletions Libraries/Image/RCTImageView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ - (void)setResizeMode:(RCTResizeMode)resizeMode
}
}

- (void)setInternal_analyticTag:(NSString *)internal_analyticTag {
if (_internal_analyticTag != internal_analyticTag) {
_internal_analyticTag = internal_analyticTag;
_needsReload = YES;
}
}

- (void)cancelImageLoad
{
[_loaderRequest cancel];
Expand Down Expand Up @@ -341,6 +348,7 @@ - (void)reloadImage
attribution:{
.nativeViewTag = [self.reactTag intValue],
.surfaceId = [self.rootTag intValue],
.analyticTag = self.internal_analyticTag
}
progressBlock:progressHandler
partialLoadBlock:partialLoadHandler
Expand Down
1 change: 1 addition & 0 deletions Libraries/Image/RCTImageViewManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ - (UIView *)view
RCT_EXPORT_VIEW_PROPERTY(onLoad, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onLoadEnd, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(resizeMode, RCTResizeMode)
RCT_EXPORT_VIEW_PROPERTY(internal_analyticTag, NSString)
RCT_REMAP_VIEW_PROPERTY(source, imageSources, NSArray<RCTImageSource *>);
RCT_CUSTOM_VIEW_PROPERTY(tintColor, UIColor, RCTImageView)
{
Expand Down
1 change: 1 addition & 0 deletions Libraries/Image/__tests__/__snapshots__/Image-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exports[`<Image /> should render as <Image> when mocked 1`] = `
exports[`<Image /> should render as <RCTImageView> when not mocked 1`] = `
<RCTImageView
internal_analyticTag={null}
resizeMode="cover"
source={
Array [
Expand Down

0 comments on commit 60b7a30

Please sign in to comment.