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

Callback support for animated drawables #676

Merged

Conversation

sagar-viradiya
Copy link
Contributor

@sagar-viradiya sagar-viradiya commented Feb 21, 2021

- Add getter and setter extension for start and end callbacks on ImageRequest.Builder.
- Apply start and end callbacks through Animatable2.AnimationCallback and Animatable2Compat.AnimationCallback in the ImageDecoderDecoder.kt and GifDecoder.kt respectively.
- Fix import order
- Fix code formatting issue
- Remove super call from Animation callbacks.
- Minor code enhancements.
- Instrumentation testing on callback for animated drawables
- Moved only decoding part to interruptible source in ImageDecoderDecoder.kt
.data("${ContentResolver.SCHEME_FILE}:///android_asset/animated.gif")
.build()
imageLoader.enqueue(imageRequest)
delay(5000)
Copy link
Member

Choose a reason for hiding this comment

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

delay could make the test flaky if the emulator is slow. I'd recommend converting isStartCalled and isEndCalled to MutableStateFlow(false). Then you can start the image request and await them being set to true like here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have made the suggested changes. I have one concern here though. What if in the future due to some changes callback won't get triggered, Wouldn't it lead to suspension forever?

Copy link
Member

Choose a reason for hiding this comment

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

Yep! We could probably add a listener for onSuccess/onError/onCancel, but it awaiting forever is ok too. After ~25 minutes the tests will timeout. By migrating to use the state flow we guarantee that the test will only fail/stall if it's been broken.

- Replace delay in the AnimationCallbacksTest.kt with StateFlow to avoid flaky test.
- Fix typo in the GifDecoder.kt
@sagar-viradiya sagar-viradiya marked this pull request as ready for review February 26, 2021 17:31
Copy link
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.

Great work, thanks 🙏

@colinrtwhite colinrtwhite merged commit 853b396 into coil-kt:master Feb 26, 2021
@rundavidrun
Copy link

Thanks again for this @sagar-viradiya. Works like a charm!

colinrtwhite pushed a commit that referenced this pull request Oct 5, 2022
* Support for start and end callbacks for animated drawables

- Add getter and setter extension for start and end callbacks on ImageRequest.Builder.
- Apply start and end callbacks through Animatable2.AnimationCallback and Animatable2Compat.AnimationCallback in the ImageDecoderDecoder.kt and GifDecoder.kt respectively.

* Minor code refactoring

- Fix import order
- Fix code formatting issue

* API dump.

* PR review changes.

- Remove super call from Animation callbacks.
- Minor code enhancements.

* Testing and decoder changes

- Instrumentation testing on callback for animated drawables
- Moved only decoding part to interruptible source in ImageDecoderDecoder.kt

* PR review changes

- Replace delay in the AnimationCallbacksTest.kt with StateFlow to avoid flaky test.
- Fix typo in the GifDecoder.kt
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.

Provide callback when animated GIF is done playing
3 participants