Skip to content

Mutate crossfade start/end drawables#572

Merged
colinrtwhite merged 4 commits into
coil-kt:masterfrom
Raenar4k:mutate_crossfade_drawable
Nov 5, 2020
Merged

Mutate crossfade start/end drawables#572
colinrtwhite merged 4 commits into
coil-kt:masterfrom
Raenar4k:mutate_crossfade_drawable

Conversation

@Raenar4k
Copy link
Copy Markdown
Contributor

Fixes #571

* 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
Copy link
Copy Markdown
Member

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.

class CrossfadeDrawable @JvmOverloads constructor(
private var start: Drawable?,
start: Drawable?,
private val end: Drawable?,
Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor Author

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)

Copy link
Copy Markdown
Contributor Author

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.


this.start = start?.mutate()
start?.callback = this
end?.callback = this
Copy link
Copy Markdown
Member

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.

@colinrtwhite
Copy link
Copy Markdown
Member

Thanks for finding + fixing this!

@Raenar4k Raenar4k changed the title Mutate crossfade start drawable Mutate crossfade start/end drawables Nov 4, 2020
@Raenar4k Raenar4k force-pushed the mutate_crossfade_drawable branch from dc45bb0 to faff35d Compare November 4, 2020 23:03
@Raenar4k Raenar4k force-pushed the mutate_crossfade_drawable branch from faff35d to fb0c458 Compare November 4, 2020 23:11
Copy link
Copy Markdown
Member

@colinrtwhite colinrtwhite left a comment

Choose a reason for hiding this comment

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

Awesome, thanks!

@colinrtwhite colinrtwhite merged commit f724df5 into coil-kt:master Nov 5, 2020
IljaKosynkin pushed a commit to IljaKosynkin/coil that referenced this pull request Nov 6, 2020
* 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)
colinrtwhite pushed a commit that referenced this pull request Oct 5, 2022
* 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)
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.

Using crossfade together with placeholder changes placeholder drawable alpha

2 participants