Callback support for animated drawables#676
Conversation
- 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.
…nhancement/gif-callback
…nhancement/gif-callback
- 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
|
Thanks again for this @sagar-viradiya. Works like a charm! |
* 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
Uh oh!
There was an error while loading. Please reload this page.