Skip to content

Commit ec20980

Browse files
committed
invalidDrawable when value change.
1 parent 0cb8f47 commit ec20980

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

library/src/main/java/com/opensource/svgaplayer/SVGAImageView.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,22 @@ class SVGADrawable(val videoItem: SVGAVideoEntity, val dynamicItem: SVGADynamicE
2323
constructor(videoItem: SVGAVideoEntity): this(videoItem, SVGADynamicEntity())
2424

2525
var cleared = true
26+
internal set (value) {
27+
if (field == value) {
28+
return
29+
}
30+
field = value
31+
invalidateSelf()
32+
}
2633

2734
var currentFrame = 0
28-
internal set
35+
internal set (value) {
36+
if (field == value) {
37+
return
38+
}
39+
field = value
40+
invalidateSelf()
41+
}
2942

3043
override fun draw(canvas: Canvas?) {
3144
if (cleared) {
@@ -126,7 +139,6 @@ open class SVGAImageView : ImageView {
126139
animator.repeatCount = if (loops <= 0) 99999 else loops - 1
127140
animator.addUpdateListener {
128141
drawable.currentFrame = animator.animatedValue as Int
129-
drawable.invalidateSelf()
130142
callback?.onStep(drawable.currentFrame, ((drawable.currentFrame + 1).toDouble() / drawable.videoItem.frames.toDouble()))
131143
}
132144
animator.addListener(object : Animator.AnimatorListener {
@@ -138,7 +150,6 @@ open class SVGAImageView : ImageView {
138150
if (!clearsAfterStop) {
139151
if (fillMode == FillMode.Backward) {
140152
drawable.currentFrame = 0
141-
drawable.invalidateSelf()
142153
}
143154
}
144155
callback?.onFinished()
@@ -164,7 +175,6 @@ open class SVGAImageView : ImageView {
164175
animator?.cancel()
165176
(drawable as? SVGADrawable)?.let {
166177
it.cleared = clear
167-
it.invalidateSelf()
168178
}
169179
}
170180

@@ -182,7 +192,6 @@ open class SVGAImageView : ImageView {
182192
pauseAnimation()
183193
val drawable = drawable as? SVGADrawable ?: return
184194
drawable.currentFrame = frame
185-
drawable.invalidateSelf()
186195
if (andPlay) {
187196
startAnimation()
188197
animator?.let {

0 commit comments

Comments
 (0)