Skip to content

Commit 96aaa21

Browse files
authored
Merge pull request #71 from r-ralph/fix-index
Fix index calculation
2 parents 7097a85 + 37da271 commit 96aaa21

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

apng-drawable/src/main/kotlin/com/linecorp/apng/ApngDrawable.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import java.io.File
4040
import java.io.FileNotFoundException
4141
import java.io.IOException
4242
import java.io.InputStream
43-
import kotlin.math.max
43+
import kotlin.math.min
4444

4545
/**
4646
* An animated [Drawable] that plays the frames of an animated PNG.
@@ -124,7 +124,7 @@ class ApngDrawable @VisibleForTesting internal constructor(
124124
* The first loop is `0` and last loop is same with `[loopCount] - 1`
125125
*/
126126
val currentLoopIndex: Int
127-
get() = max(currentLoopIndexInternal, loopCount - 1)
127+
get() = min(currentLoopIndexInternal, loopCount - 1)
128128

129129
/**
130130
* The corresponding frame index with the elapsed time of the animation. This value indicates
@@ -335,8 +335,8 @@ class ApngDrawable @VisibleForTesting internal constructor(
335335
repeatAnimationCallbacks.forEach {
336336
// TODO: Remove `onRepeat` invocation at the next version.
337337
@Suppress("DEPRECATION")
338-
it.onRepeat(this, currentLoopIndexInternal + 1)
339-
it.onAnimationRepeat(this, currentLoopIndexInternal)
338+
it.onRepeat(this, currentLoopIndexInternal + 2)
339+
it.onAnimationRepeat(this, currentLoopIndexInternal + 1)
340340
}
341341
}
342342
}

0 commit comments

Comments
 (0)