Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Add Animator.lifecycleObserver #353

Merged
merged 2 commits into from
Mar 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package io.goooler.demoapp.base.util

import android.animation.Animator
import android.app.Activity
import android.content.ContentUris
import android.content.Context
Expand Down Expand Up @@ -40,8 +41,10 @@ import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.commit
import androidx.fragment.app.findFragment
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleCoroutineScope
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.coroutineScope
import androidx.lifecycle.findViewTreeLifecycleOwner
Expand Down Expand Up @@ -393,6 +396,28 @@ fun TextView.setOnEditorConfirmActionListener(listener: (TextView) -> Unit) {
}
}

// ---------------------Anim-------------------------------//

val Animator.lifecycleObserver: LifecycleObserver get() = object : DefaultLifecycleObserver {
override fun onStart(owner: LifecycleOwner) {
start()
}

override fun onResume(owner: LifecycleOwner) {
resume()
}

override fun onPause(owner: LifecycleOwner) {
pause()
}

override fun onDestroy(owner: LifecycleOwner) {
removeAllListeners()
end()
cancel()
}
}

// ---------------------Context-------------------------------//

fun Context.addDynamicShortcutCompat(id: String, shortcut: ShortcutInfoCompat) {
Expand Down