Last active
February 26, 2022 18:02
-
-
Save evilthreads669966/0a9d443b7255c0285744a709eb792a18 to your computer and use it in GitHub Desktop.
type safe way for passing objects when performing a NavHostController's navigation function. saving the arguments to the navcontroller instead.
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
fun <T: Parcelable> NavHostController.putParcelables(key: String, parcelables: ArrayList<T>) = currentBackStackEntry?.arguments?.putParcelableArrayList(key, parcelables) | |
fun <T: Parcelable> NavHostController.getParcelables(key: String) = previousBackStackEntry?.arguments?.getParcelableArrayList<T>(key) | |
fun <T: Parcelable> NavHostController.putParcelable(key: String, parcelable: T) = currentBackStackEntry?.arguments?.putParcelable(key, parcelable) | |
fun <T: Parcelable> NavHostController.getParcelable(key: String) = previousBackStackEntry?.arguments?.getParcelable<T>(key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment