Skip to content
This repository was archived by the owner on Jan 10, 2020. It is now read-only.

Commit 07ce61e

Browse files
m1gafacebook-github-bot
authored andcommitted
Android: add playOnce()
Summary: Add `playOnce()` that will play the animation only once and stops at the end Closes #94 Differential Revision: D4385175 Pulled By: lozzle fbshipit-source-id: 8b2f65003bfb9a3cfc040e90385369d13e1025c5
1 parent 4bd6cc0 commit 07ce61e

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ kfDrawable.stopAnimation();
149149

150150
// Stops the animation when the current animation ends.
151151
kfDrawable.stopAnimationAtLoopEnd();
152+
153+
// Starts the animation and plays it once. Will stop at the end
154+
kfDrawable.playOnce();
152155
```
153156

154157
### Mobile Frameworks

android/keyframes/src/main/java/com/facebook/keyframes/KeyframesDrawable.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,13 @@ public void startAnimation() {
290290
mKeyframesDrawableAnimationCallback.start();
291291
}
292292

293+
/**
294+
* Starts the animation and plays it once
295+
*/
296+
public void playOnce() {
297+
mKeyframesDrawableAnimationCallback.playOnce();
298+
}
299+
293300
/**
294301
* Stops the animation callbacks for this drawable immediately.
295302
*/

android/keyframes/src/main/java/com/facebook/keyframes/KeyframesDrawableAnimationCallback.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ public void start() {
104104
postCallback();
105105
}
106106

107+
/**
108+
* Starts the animation and plays it once
109+
*/
110+
public void playOnce() {
111+
mStopAtLoopEnd = true;
112+
mStartTimeMillis = 0;
113+
mCurrentLoopNumber = 0;
114+
cancelCallback();
115+
postCallback();
116+
}
117+
107118
/**
108119
* Stops the callbacks animation and resets the start time.
109120
*/

0 commit comments

Comments
 (0)