-
Notifications
You must be signed in to change notification settings - Fork 683
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
Mutate crossfade start/end drawables #572
Mutate crossfade start/end drawables #572
Conversation
@@ -24,14 +24,14 @@ import kotlin.math.roundToInt | |||
* | |||
* NOTE: The animation can only be executed once as the [start] drawable is dereferenced at the end of the transition. | |||
* | |||
* @param start The [Drawable] to crossfade from. | |||
* @param start The [Drawable] to crossfade from. Will be mutated to prevent modifying alpha of original drawable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to mention mutation in the docs.
* @param end The [Drawable] to crossfade to. | ||
* @param scale The scaling algorithm for [start] and [end]. | ||
* @param durationMillis The duration of the crossfade animation. | ||
* @param fadeStart If false, the start drawable will not fade out while the end drawable fades in. | ||
*/ | ||
class CrossfadeDrawable @JvmOverloads constructor( | ||
private var start: Drawable?, | ||
start: Drawable?, | ||
private val end: Drawable?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably mutate end
as well since it could be loaded from resources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, didn't think about that! Since we can provide something like error placeholder. Tested it in sample, same bug
#571 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Not sure if tests are good enough, they are testing drawable changes, but with a bit of a hack - since percent of animation is tied to SystemClock
and can't be influenced directly.
private var startTimeMillis = 0L | ||
private var maxAlpha = 255 | ||
private var state = STATE_START | ||
|
||
init { | ||
require(durationMillis > 0) { "durationMillis must be > 0." } | ||
|
||
this.start = start?.mutate() | ||
start?.callback = this | ||
end?.callback = this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be this.start
and this.end
? drawable.mutate
is supposed to return the same drawable, but there's nothing to prevent a bad drawable from returning a new drawable.
Thanks for finding + fixing this! |
dc45bb0
to
faff35d
Compare
…es (coil-kt#571) Remove mention of drawable mutation from CrossfadeDrawable doc (coil-kt#571)
faff35d
to
fb0c458
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks!
* Add failing test for crossfade drawable alpha bug (coil-kt#571) * Change CrossfadeDrawable constructor to mutate start drawable (coil-kt#571) * Add test for both start/end drawables in CrossfadeDrawableTest (coil-kt#571) * Change CrossfadeDrawable constructor to mutate both start/end drawables (coil-kt#571) Remove mention of drawable mutation from CrossfadeDrawable doc (coil-kt#571)
* Add failing test for crossfade drawable alpha bug (#571) * Change CrossfadeDrawable constructor to mutate start drawable (#571) * Add test for both start/end drawables in CrossfadeDrawableTest (#571) * Change CrossfadeDrawable constructor to mutate both start/end drawables (#571) Remove mention of drawable mutation from CrossfadeDrawable doc (#571)
Fixes #571