Skip to content

Commit

Permalink
Re-land D2656590 in iOS repo which is the source of truth
Browse files Browse the repository at this point in the history
Reviewed By: newobj

Differential Revision: D2660019

fb-gh-sync-id: 7cc183888f88d9971f59b23f45a86b5aa0391909
  • Loading branch information
olinotteghem authored and facebook-github-bot-7 committed Nov 16, 2015
1 parent f331d2a commit e4f0971
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ public void setTintColor(ReactImageView view, @Nullable Integer tintColor) {
}
}

@ReactProp(name = "progressiveRenderingEnabled")
public void setProgressiveRenderingEnabled(ReactImageView view, boolean enabled) {
view.setProgressiveRenderingEnabled(enabled);
}

@ReactProp(name = "fadeDuration")
public void setFadeDuration(ReactImageView view, int durationMs) {
view.setFadeDuration(durationMs);
}

@Override
protected void onAfterUpdateTransaction(ReactImageView view) {
super.onAfterUpdateTransaction(view);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
public class ReactImageView extends GenericDraweeView {

private static final int REMOTE_IMAGE_FADE_DURATION_MS = 300;
public static final String TAG = ReactImageView.class.getSimpleName();

/*
* Implementation note re rounded corners:
Expand Down Expand Up @@ -107,7 +106,8 @@ public void process(Bitmap output, Bitmap source) {
private final RoundedCornerPostprocessor mRoundedCornerPostprocessor;
private final @Nullable Object mCallerContext;
private @Nullable ControllerListener mControllerListener;
private int mImageFadeDuration = -1;
private int mFadeDurationMs = -1;
private boolean mProgressiveRenderingEnabled;

// We can't specify rounding in XML, so have to do so here
private static GenericDraweeHierarchy buildHierarchy(Context context) {
Expand Down Expand Up @@ -169,6 +169,16 @@ public void setSource(@Nullable String source) {
mIsDirty = true;
}

public void setProgressiveRenderingEnabled(boolean enabled) {
mProgressiveRenderingEnabled = enabled;
// no worth marking as dirty if it already rendered..
}

public void setFadeDuration(int durationMs) {
mFadeDurationMs = durationMs;
// no worth marking as dirty if it already rendered..
}

public void maybeUpdateView() {
if (!mIsDirty) {
return;
Expand All @@ -192,8 +202,9 @@ public void maybeUpdateView() {
roundingParams.setCornersRadius(hierarchyRadius);
roundingParams.setBorder(mBorderColor, mBorderWidth);
hierarchy.setRoundingParams(roundingParams);
hierarchy.setFadeDuration(mImageFadeDuration >= 0
? mImageFadeDuration
hierarchy.setFadeDuration(
mFadeDurationMs >= 0
? mFadeDurationMs
: mIsLocalImage ? 0 : REMOTE_IMAGE_FADE_DURATION_MS);

Postprocessor postprocessor = usePostprocessorScaling ? mRoundedCornerPostprocessor : null;
Expand All @@ -203,6 +214,7 @@ public void maybeUpdateView() {
ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(mUri)
.setPostprocessor(postprocessor)
.setResizeOptions(resizeOptions)
.setProgressiveRenderingEnabled(mProgressiveRenderingEnabled)
.build();

DraweeController draweeController = mDraweeControllerBuilder
Expand All @@ -224,13 +236,6 @@ public void setControllerListener(ControllerListener controllerListener) {
maybeUpdateView();
}

// VisibleForTesting
public void setImageFadeDuration(int imageFadeDuration) {
mImageFadeDuration = imageFadeDuration;
mIsDirty = true;
maybeUpdateView();
}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
Expand Down

0 comments on commit e4f0971

Please sign in to comment.