Improve spoiler performance by stopping animation when backgrounded.

This commit is contained in:
Cody Henthorne
2023-06-12 13:11:15 -04:00
committed by GitHub
parent 7e24252447
commit 36aa8623da
2 changed files with 39 additions and 2 deletions

View File

@@ -6,6 +6,9 @@ import androidx.annotation.DrawableRes
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintSet
import androidx.core.view.doOnNextLayout
import androidx.fragment.app.Fragment
import androidx.fragment.app.findFragment
import androidx.lifecycle.Lifecycle
var View.visible: Boolean
get() {
@@ -56,3 +59,15 @@ fun TextView.setRelativeDrawables(
bottom
)
}
/**
* Get a lifecycle associated with this view. Care must be taken to ensure
* if activity fallback occurs that the context of the view is correct.
*/
fun View.getLifecycle(): Lifecycle {
return try {
findFragment<Fragment>().viewLifecycleOwner.lifecycle
} catch (e: IllegalStateException) {
ViewUtil.getActivityLifecycle(this)!!
}
}