Skip to content

Commit

Permalink
Extend Android ImageViewManager to support analyticsTag prop
Browse files Browse the repository at this point in the history
Summary:
This diff extends the Android Image View manager to support the new analyticsTag prop. this prop is going to be used to track performance for images in android

changelog: [Android][Added] Add analyticsTag prop into ImageView component

Reviewed By: JoshuaGross

Differential Revision: D20880602

fbshipit-source-id: e302e8fa83706e6517b228d44a3094a1686830f7
  • Loading branch information
mdvacca authored and facebook-github-bot committed Apr 7, 2020
1 parent f7b9033 commit 72150f5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package com.facebook.react.views.image;

import androidx.annotation.Nullable;
import com.facebook.react.uimanager.ThemedReactContext;

/**
Expand All @@ -21,5 +22,5 @@ public interface ReactCallerContextFactory {
* @param reactContext {@link ThemedReactContext} used to create the {@link ReactImageView}
* @return an {@link Object} that represents the CallerContext.
*/
Object getOrCreateCallerContext(ThemedReactContext reactContext);
Object getOrCreateCallerContext(ThemedReactContext reactContext, @Nullable String analyticTag);
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public Object getCallerContext() {
public ReactImageView createViewInstance(ThemedReactContext context) {
Object callerContext =
mCallerContextFactory != null
? mCallerContextFactory.getOrCreateCallerContext(context)
? mCallerContextFactory.getOrCreateCallerContext(context, null)
: getCallerContext();
return new ReactImageView(
context, getDraweeControllerBuilder(), mGlobalImageLoadListener, callerContext);
Expand All @@ -124,6 +124,15 @@ public void setBlurRadius(ReactImageView view, float blurRadius) {
view.setBlurRadius(blurRadius);
}

@ReactProp(name = "analyticTag")
public void setAnalyticsTag(ReactImageView view, @Nullable String analyticTag) {
if (mCallerContextFactory != null) {
view.updateCallerContext(
mCallerContextFactory.getOrCreateCallerContext(
(ThemedReactContext) view.getContext(), analyticTag));
}
}

// In JS this is Image.props.defaultSource
@ReactProp(name = "defaultSrc")
public void setDefaultSource(ReactImageView view, @Nullable String source) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public class ReactImageView extends GenericDraweeView {
private static final Matrix sInverse = new Matrix();
private ImageResizeMethod mResizeMethod = ImageResizeMethod.AUTO;

public void updateCallerContext(@Nullable Object callerContext) {
mCallerContext = callerContext;
mIsDirty = true;
}

private class RoundedCornerPostprocessor extends BasePostprocessor {

void getRadii(Bitmap source, float[] computedCornerRadii, float[] mappedRadii) {
Expand Down Expand Up @@ -197,7 +202,7 @@ public CloseableReference<Bitmap> process(Bitmap source, PlatformBitmapFactory b
private @Nullable ControllerListener mControllerListener;
private @Nullable ControllerListener mControllerForTesting;
private @Nullable GlobalImageLoadListener mGlobalImageLoadListener;
private final @Nullable Object mCallerContext;
private @Nullable Object mCallerContext;
private int mFadeDurationMs = -1;
private boolean mProgressiveRenderingEnabled;
private ReadableMap mHeaders;
Expand Down

0 comments on commit 72150f5

Please sign in to comment.