Fix NPE in spoiler renderer.

This commit is contained in:
Cody Henthorne
2023-06-21 10:10:01 -04:00
parent d989d02af9
commit 07bd8b2fa3
2 changed files with 3 additions and 3 deletions

View File

@@ -56,7 +56,7 @@ class SpoilerRendererDelegate @JvmOverloads constructor(
view.addOnAttachStateChangeListener(object : OnAttachStateChangeListener {
override fun onViewDetachedFromWindow(v: View) = stopAnimating()
override fun onViewAttachedToWindow(v: View) {
view.getLifecycle().addObserver(object : DefaultLifecycleObserver {
view.getLifecycle()?.addObserver(object : DefaultLifecycleObserver {
override fun onResume(owner: LifecycleOwner) {
canAnimate = true
systemAnimationsEnabled = !AccessibilityUtil.areAnimationsDisabled(view.context)

View File

@@ -64,10 +64,10 @@ fun TextView.setRelativeDrawables(
* 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 {
fun View.getLifecycle(): Lifecycle? {
return try {
findFragment<Fragment>().viewLifecycleOwner.lifecycle
} catch (e: IllegalStateException) {
ViewUtil.getActivityLifecycle(this)!!
ViewUtil.getActivityLifecycle(this)
}
}