Skip to content

Commit

Permalink
Delete ReactFeatureFlags.enableRoundedCornerPostprocessing
Browse files Browse the repository at this point in the history
Summary:
Rounded corner postprocessing has been disabled for 2 months now, and [metrics neutral](https://www.internalfb.com/intern/qe2/react_fabric_marketplace_home_android_universe/react_fabric_disable_rounded_corner_postprocess_android/setup/config). Removing the flag and associated codepaths.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D33953645

fbshipit-source-id: b0e5a6068114d74292f17450a22816f19cae6f15
  • Loading branch information
genkikondo authored and facebook-github-bot committed Feb 2, 2022
1 parent 09e418e commit 08faa13
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,4 @@ public static boolean doesUseOverflowInset() {

/** TODO: T103427072 Delete ReactFeatureFlags.enableNestedTextOnPressEventFix */
public static boolean enableNestedTextOnPressEventFix = true;

/** TODO: T107492383 Delete this flag. Enables postprocessor for rounded corners for Image */
public static boolean enableRoundedCornerPostprocessing = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ rn_android_library(
react_native_dep("third-party/java/jsr-305:jsr-305"),
react_native_target("java/com/facebook/react/bridge:bridge"),
react_native_target("java/com/facebook/react/common:common"),
react_native_target("java/com/facebook/react/config:config"),
react_native_target("java/com/facebook/react/module/annotations:annotations"),
react_native_target("java/com/facebook/react/uimanager:uimanager"),
react_native_target("java/com/facebook/react/modules/fresco:fresco"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
Expand Down Expand Up @@ -48,7 +46,6 @@
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.common.build.ReactBuildConfig;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.modules.fresco.ReactNetworkImageRequest;
import com.facebook.react.uimanager.FloatUtil;
import com.facebook.react.uimanager.PixelUtil;
Expand All @@ -70,25 +67,11 @@
public class ReactImageView extends GenericDraweeView {

public static final int REMOTE_IMAGE_FADE_DURATION_MS = 300;

public static final String REMOTE_TRANSPARENT_BITMAP_URI =
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=";

private static float[] sComputedCornerRadii = new float[4];

/*
* Implementation note re rounded corners:
*
* Fresco's built-in rounded corners only work for 'cover' resize mode -
* this is a limitation in Android itself. Fresco has a workaround for this, but
* it requires knowing the background color.
*
* So for the other modes, we use a postprocessor.
* Because the postprocessor uses a modified bitmap, that would just get cropped in
* 'cover' mode, so we fall back to Fresco's normal implementation.
*/
private static final Matrix sMatrix = new Matrix();
private static final Matrix sInverse = new Matrix();
private ImageResizeMethod mResizeMethod = ImageResizeMethod.AUTO;

public void updateCallerContext(@Nullable Object callerContext) {
Expand All @@ -98,61 +81,6 @@ public void updateCallerContext(@Nullable Object callerContext) {
}
}

private class RoundedCornerPostprocessor extends BasePostprocessor {

void getRadii(Bitmap source, float[] computedCornerRadii, float[] mappedRadii) {
mScaleType.getTransform(
sMatrix,
new Rect(0, 0, source.getWidth(), source.getHeight()),
source.getWidth(),
source.getHeight(),
0.0f,
0.0f);
sMatrix.invert(sInverse);

mappedRadii[0] = sInverse.mapRadius(computedCornerRadii[0]);
mappedRadii[1] = mappedRadii[0];

mappedRadii[2] = sInverse.mapRadius(computedCornerRadii[1]);
mappedRadii[3] = mappedRadii[2];

mappedRadii[4] = sInverse.mapRadius(computedCornerRadii[2]);
mappedRadii[5] = mappedRadii[4];

mappedRadii[6] = sInverse.mapRadius(computedCornerRadii[3]);
mappedRadii[7] = mappedRadii[6];
}

@Override
public void process(Bitmap output, Bitmap source) {
getCornerRadii(sComputedCornerRadii);

output.setHasAlpha(true);
if (FloatUtil.floatsEqual(sComputedCornerRadii[0], 0f)
&& FloatUtil.floatsEqual(sComputedCornerRadii[1], 0f)
&& FloatUtil.floatsEqual(sComputedCornerRadii[2], 0f)
&& FloatUtil.floatsEqual(sComputedCornerRadii[3], 0f)) {
super.process(output, source);
return;
}
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
Canvas canvas = new Canvas(output);

float[] radii = new float[8];

getRadii(source, sComputedCornerRadii, radii);

Path pathForBorderRadius = new Path();

pathForBorderRadius.addRoundRect(
new RectF(0, 0, source.getWidth(), source.getHeight()), radii, Path.Direction.CW);

canvas.drawPath(pathForBorderRadius, paint);
}
}

// Fresco lacks support for repeating images, see https://github.com/facebook/fresco/issues/1575
// We implement it here as a postprocessing step.
private static final Matrix sTileMatrix = new Matrix();
Expand Down Expand Up @@ -198,7 +126,6 @@ public CloseableReference<Bitmap> process(Bitmap source, PlatformBitmapFactory b
private Shader.TileMode mTileMode = ImageResizeMode.defaultTileMode();
private boolean mIsDirty;
private final AbstractDraweeControllerBuilder mDraweeControllerBuilder;
private @Nullable RoundedCornerPostprocessor mRoundedCornerPostprocessor;
private @Nullable TilePostprocessor mTilePostprocessor;
private @Nullable IterativeBoxBlurPostProcessor mIterativeBoxBlurPostProcessor;
private @Nullable ReactImageDownloadListener mDownloadListener;
Expand Down Expand Up @@ -353,11 +280,6 @@ public void setBorderRadius(float borderRadius, int position) {
public void setScaleType(ScalingUtils.ScaleType scaleType) {
if (mScaleType != scaleType) {
mScaleType = scaleType;
if (shouldUseRoundedCornerPostprocessing()) {
mRoundedCornerPostprocessor = new RoundedCornerPostprocessor();
} else {
mRoundedCornerPostprocessor = null;
}
mIsDirty = true;
}
}
Expand Down Expand Up @@ -530,9 +452,6 @@ public void maybeUpdateView() {
mBackgroundImageDrawable.setRadii(roundingParams.getCornersRadii());
hierarchy.setBackgroundImage(mBackgroundImageDrawable);
}
if (shouldUseRoundedCornerPostprocessing()) {
roundingParams.setCornersRadius(0);
}
roundingParams.setBorder(mBorderColor, mBorderWidth);
if (mOverlayColor != Color.TRANSPARENT) {
roundingParams.setOverlayColor(mOverlayColor);
Expand All @@ -547,9 +466,6 @@ public void maybeUpdateView() {
: mImageSource.isResource() ? 0 : REMOTE_IMAGE_FADE_DURATION_MS);

List<Postprocessor> postprocessors = new LinkedList<>();
if (mRoundedCornerPostprocessor != null) {
postprocessors.add(mRoundedCornerPostprocessor);
}
if (mIterativeBoxBlurPostProcessor != null) {
postprocessors.add(mIterativeBoxBlurPostProcessor);
}
Expand Down Expand Up @@ -647,12 +563,6 @@ private boolean isTiled() {
return mTileMode != Shader.TileMode.CLAMP;
}

private boolean shouldUseRoundedCornerPostprocessing() {
return mScaleType != ScalingUtils.ScaleType.CENTER_CROP
&& mScaleType != ScalingUtils.ScaleType.FOCUS_CROP
&& ReactFeatureFlags.enableRoundedCornerPostprocessing;
}

private void setSourceImage() {
mImageSource = null;
if (mSources.isEmpty()) {
Expand Down

0 comments on commit 08faa13

Please sign in to comment.