Created
November 18, 2021 15:19
-
-
Save raxityo/beacbc5f7169f8622a850bbc6c386242 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Execute a callback on the main scope after given delay. | |
* | |
* @param timeMillis delay in milliseconds | |
* @param callback callback to execute after the delay | |
*/ | |
fun View.lifecycleAwarePostDelayed(timeMillis: Long, callback: () -> Unit) { | |
findViewTreeLifecycleOwner()?.lifecycle?.coroutineScope?.launch(Dispatchers.Main) { | |
delay(timeMillis) | |
callback() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment