ZieIony / Carbon

Material Design implementation for Android 4.0+. Shadows, ripples, vectors, fonts, animations, widgets, rounded corners and more.

Home Page:https://androidreclib.wordpress.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CornerRadius animator effect from 5f to 0f will lead the view flashing once

tangye1234 opened this issue · comments

The code:

RoundedCornersView frame = (RoundedCornersView) view;
ObjectAnimator radiusAnimator = ObjectAnimator.ofFloat(frame, "cornerRadius", 5f, 0f);
radiusAnimator.start();

The view is a carbon FrameLayout with an ImageView inside.

We will see the view's corner radius animates from 5 to 0, and at the end, the view flashes once.

If I change the animation to 5f - 1f, there is no problem then.
So I think it is the code below which leads to this problem.

    private void updateCorners() {
        if (cornerRadius > 0) {
            cornerRadius = Math.min(cornerRadius, Math.min(getWidth(), getHeight()) / 2.0f);
            if (Carbon.IS_LOLLIPOP && renderingMode == RenderingMode.Auto) {
                setClipToOutline(true);
                setOutlineProvider(ShadowShape.viewOutlineProvider);
            } else {
                cornersMask = new Path();
                cornersMask.addRoundRect(new RectF(0, 0, getWidth(), getHeight()), cornerRadius, cornerRadius, Path.Direction.CW);
                cornersMask.setFillType(Path.FillType.INVERSE_WINDING);
            }
        } else if (Carbon.IS_LOLLIPOP) {
            setOutlineProvider(ViewOutlineProvider.BOUNDS);   // it rebuilds the outline, then causes the problem
        }
    }

Well, I finally was able to find the actual reason for the view to flash. Unfortunately it's not Carbon, but Anroid framework. There's a thing called ViewOutlineProvider, which provides paths for the framework to clip views to. If you use a round rect path with corner radius < 1, then the view becomes transparent. That's what you see as flashing. I was able to reproduce this issue using pure Android widget:

image

button.clipToOutline = true
button.outlineProvider = object : ViewOutlineProvider() {
    override fun getOutline(p0: View, p1: Outline) {
        p1.setRoundRect(0, 0, p0.width, p0.height, 0.2f)
    }
}

I'll try to workaround it somehow.

Carbon now clamps cornerRadius to 0 if it's less than 1.