Created
January 8, 2021 06:49
-
-
Save hi-manshu/e9d4f4fd4fc997743d243a480c15c473 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| inline fun <reified T : Any> Activity.launchActivity( | |
| requestCode: Int = -1, | |
| options: Bundle? = null, | |
| noinline init: Intent.() -> Unit = {}) { | |
| val intent = newIntent<T>(this) | |
| intent.init() | |
| startActivityForResult(intent, requestCode, options) | |
| overridePendingTransition(R.anim.slide_up, R.anim.no_change) | |
| } | |
| inline fun <reified T : Any> Fragment.launchActivity( | |
| requestCode: Int = -1, | |
| options: Bundle? = null, | |
| noinline init: Intent.() -> Unit = {}) { | |
| val intent = newIntent<T>(requireContext()) | |
| intent.init() | |
| startActivityForResult(intent, requestCode, options) | |
| requireActivity().overridePendingTransition(R.anim.slide_up, R.anim.no_change) | |
| } | |
| inline fun <reified T : Any> Activity.launchActivity( | |
| options: Bundle? = null, | |
| noinline init: Intent.() -> Unit = {}) { | |
| val intent = newIntent<T>(this) | |
| intent.init() | |
| startActivity(intent, options) | |
| overridePendingTransition(R.anim.slide_up, R.anim.no_change) | |
| } | |
| inline fun <reified T : Any> Fragment.launchActivity( | |
| options: Bundle? = null, | |
| noinline init: Intent.() -> Unit = {}) { | |
| val intent = newIntent<T>(requireContext()) | |
| intent.init() | |
| startActivity(intent, options) | |
| requireActivity().overridePendingTransition(R.anim.slide_up, R.anim.no_change) | |
| } | |
| inline fun <reified T : Any> newIntent(context: Context): Intent = | |
| Intent(context, T::class.java) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment