Skip to content

Commit 8944e99

Browse files
committed
cancel animator while onDetachedFromWindow.
1 parent 24e47a9 commit 8944e99

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

app/src/main/res/layout/activity_simple.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
<com.opensource.svgaplayer.SVGAImageView
99
android:layout_height="match_parent"
1010
android:layout_width="match_parent"
11-
app:source="posche.svga"
12-
app:autoPlay="true"
13-
android:background="#000" />
11+
app:source="posche.svga"/>
1412

1513
</RelativeLayout>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ open class SVGAImageView : ImageView {
9494
attrs?.let { loadAttrs(it) }
9595
}
9696

97+
override fun onDetachedFromWindow() {
98+
super.onDetachedFromWindow()
99+
animator?.cancel()
100+
}
101+
97102
fun loadAttrs(attrs: AttributeSet) {
98103
val typedArray = context.theme.obtainStyledAttributes(attrs, R.styleable.SVGAImageView, 0, 0)
99104
loops = typedArray.getInt(R.styleable.SVGAImageView_loopCount, 0)

0 commit comments

Comments
 (0)