addisonElliott / SegmentedButton

Segmented Control/Button with animation for Android API 16+
Apache License 2.0
148 stars 39 forks source link

Added support for VectorDrawable #19

Closed amaslanka closed 4 years ago

amaslanka commented 4 years ago

Added checking drawable type in SegmentedButton. If the drawable is Vector, it will be converted into a bitmap. This allows to handle drawable tint/selected tint properly.

addisonElliott commented 4 years ago

Hello, thanks for the PR!

I'll hopefully spend some time checking this out in more detail to fully understand it. But, do you mind adding a "unit test" to demonstrate this feature? Essentially, just add another item to the sample activity that shows it working.

In addition, I would recommend testing the feature on a few different Android versions (I usually do API19, API21, and API26 or 27) just to be sure.

amaslanka commented 4 years ago

Hi!

Take a look at the example which I provided in the sample activity. It's tested on different API versions.

addisonElliott commented 4 years ago

Can you explain why you took VectorDrawable and converted it into a BitmapDrawable?

I changed the code to just return a VectorDrawable and the sample works out to be the same. Tinting seems to be working fine with just the VectorDrawable. (Tested on API 19 & 21)

image

amaslanka commented 4 years ago

The bug appears on API 28. The selectedDrawableTint of SegmentedButton is always applied to its drawable if the drawable type is VectorDrawable. Take a look at the screenshot.

Zrzut ekranu 2019-09-14 o 23 20 38

After converting VectorDrawable to BitmapDrawable the tint is working fine on API 28.
On lower API versions the bug doesn't appear at all.

addisonElliott commented 4 years ago

Wow, what a crazy bug. It's gone on API 29, so I made adjustments to the code to only convert from vector to bitmap in API 28. My thought process is that keeping the vector as a vector drawable is more efficient (in terms of memory) than converting to a bitmap. Although, in the end, the performance/memory differences is likely minimal.

Everything looks good! I'll add the new sample GIF and release a new version. Thanks