Sdwebimage: How to extend the GIF playback functionality?

Created on 12 Oct 2020  路  4Comments  路  Source: SDWebImage/SDWebImage

New Issue Checklist

Issue Info

Info | Value |
-------------------------|-------------------------------------|
Platform Name | all
Platform Version | all
SDWebImage Version | all
Integration Method | cocoapods
Xcode Version | all
Repro rate |
Repro with our demo prj |
Demo project link |

Issue Description and Steps

This is not a bug, just a question about adding a new feature.
I am writing an application that plays GIFs like this:
1st frame, 2nd frame, 3d frame, 2nd frame, 1st frame, etc.

And now I was able to patch SDWebImage library by adding this code:
Zrzut ekranu 2020-10-12 o 16 36 11

And the code works great.
But I thought it might be useful for community to have the option to play GIFs this way (there are many popular apps that use this style of playback: TikTok for example).

So I opened the project and decided to write an additional "bounce" option that will play GIFs this way.

But...

I have small experience with ObjectiveC. And I have no idea how to add this new "bounce" option.

So I have some questions:
Should I add a new SDWebImageOptions flag?
Or maybe I should create a new plugin (or even something else)?
And will such functionality be implemented in SDWebImage at all?

Thank you in advance for your response :)

animated image feature request

Most helpful comment

And will such functionality be implemented in SDWebImage at all?

Yes. Sounds not so hacky logic, we can add a enum (better than just BOOL value, because I asssume there may be more feature requests about the playback logic)..

typedef NS_ENUM(NSUInteger, SDAnimatedImagePlaybackMode) {
    SDAnimatedImagePlaybackModeNormal = 0, // from first to last frame and stop or next loop
    SDAnimatedImagePlaybackModeReverse, // from last frame to first frame and stop or next loop
    SDAnimatedImagePlaybackModeBounce, // from first frame to last frame and reverse again, like reciprocating
    SDAnimatedImagePlaybackModeReversedBounce, // from last frame to first frame and reverse again, like reversed reciprocating
}

What about these features above ?

All 4 comments

This is not suitable for SDWebImageOptions. The options is used for individual image request control, not about the UI rendering logic.

This is a function which works on SDAnimatedImageView. And also, SDAnimatedImagePlayer.

So the new property should be placed on these two classes.

And will such functionality be implemented in SDWebImage at all?

Yes. Sounds not so hacky logic, we can add a enum (better than just BOOL value, because I asssume there may be more feature requests about the playback logic)..

typedef NS_ENUM(NSUInteger, SDAnimatedImagePlaybackMode) {
    SDAnimatedImagePlaybackModeNormal = 0, // from first to last frame and stop or next loop
    SDAnimatedImagePlaybackModeReverse, // from last frame to first frame and stop or next loop
    SDAnimatedImagePlaybackModeBounce, // from first frame to last frame and reverse again, like reciprocating
    SDAnimatedImagePlaybackModeReversedBounce, // from last frame to first frame and reverse again, like reversed reciprocating
}

What about these features above ?

Thank you for the quick reply!
Yes, this enum with 4 modes is more universal. I will try to write a PR soon :)

I second this feature request!

Was this page helpful?
0 / 5 - 0 ratings