Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix AppCompatImageHelper applySupportImageTint VectorDrawable bug #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Caij
Copy link

@Caij Caij commented Jun 14, 2018

VectorDrawableCompat invalidateSelf -> mDelegateDrawable(BitmapDrawable) invalidateSelf ->ImageView invalidateDrawable

    public void invalidateDrawable(@NonNull Drawable dr) {
        dr isBitmapDrawable  mDrawableVectorDrawableCompat  不相等 所以不会重绘。
        if (dr == mDrawable) { 
            if (dr != null) {
                // update cached drawable dimensions if they've changed
                final int w = dr.getIntrinsicWidth();
                final int h = dr.getIntrinsicHeight();
                if (w != mDrawableWidth || h != mDrawableHeight) {
                    mDrawableWidth = w;
                    mDrawableHeight = h;
                    // updates the matrix, which is dependent on the bounds
                    configureBounds();
                }
            }
            /* we invalidate the whole view in this case because it's very
             * hard to know where the drawable actually is. This is made
             * complicated because of the offsets and transformations that
             * can be applied. In theory we could get the drawable's bounds
             * and run them through the transformation and offsets, but this
             * is probably not worth the effort.
             */
            invalidate();
        } else {
            super.invalidateDrawable(dr);
        }
    }

这个问题最终是VectorDrawableCompat的是的问题 已经提交官方修改 https://issuetracker.google.com/issues/110174719

@xyczero
Copy link
Member

xyczero commented Jun 23, 2018

  1. 关于刷新不生效的原因我有一点不同的看法,VectorDrawableCompat并没有给它内部的mDelegateDrawable设置setCallback的回调,然后导致不会刷新的原因是不是例子中的BitmapDrawable的getCallback为空,所以就没走到ImageView的invalidateDrawable方法,当然如果走进该方法后,就如您所说也是不会真正生效的。
  2. VectorDrawableCompat这个bug相对只是个特例,所以建议可以对mDelegateDrawable特殊处理下,一般的时候invalidateSelf效率更高些

@@ -148,7 +148,7 @@ private boolean applySupportImageTint() {
}
setImageDrawable(tintDrawable);
if (image == tintDrawable) {
tintDrawable.invalidateSelf();
mView.invalidate();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if( image instanceof VectorDrawableCompat) {
    mView.invalidate();
} else {
   tintDrawable.invalidateSelf();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants