From 867f4928a4b63af9420930090ff9b184222e1685 Mon Sep 17 00:00:00 2001 From: Rafael Costa Date: Sat, 9 Mar 2024 15:17:34 +0000 Subject: [PATCH] Added TestDestinationsNavigator API. --- .../testing/TestDestinationsNavigator.kt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 compose-destinations/src/main/java/com/ramcosta/composedestinations/testing/TestDestinationsNavigator.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/testing/TestDestinationsNavigator.kt b/compose-destinations/src/main/java/com/ramcosta/composedestinations/testing/TestDestinationsNavigator.kt new file mode 100644 index 00000000..2683bd40 --- /dev/null +++ b/compose-destinations/src/main/java/com/ramcosta/composedestinations/testing/TestDestinationsNavigator.kt @@ -0,0 +1,24 @@ +package com.ramcosta.composedestinations.testing + +import androidx.lifecycle.Lifecycle +import androidx.navigation.NavController +import com.ramcosta.composedestinations.navigation.DestinationsNavController +import com.ramcosta.composedestinations.navigation.DestinationsNavigator + +/** + * Creates a [DestinationsNavigator] good for testing. + * + * @param testNavController should be `TestNavHostController` from navigation testing artifact + * @param isCurrentBackStackEntryResumed allows you to control behavior of `onlyIfResumed` parameter + * on navigate calls. By default, uses the real response from [testNavController]'s current nav back stack entry. + */ +@Suppress("FunctionName") +fun TestDestinationsNavigator( + testNavController: NavController, + isCurrentBackStackEntryResumed: () -> Boolean = { + testNavController.currentBackStackEntry?.lifecycle?.currentState == Lifecycle.State.RESUMED + } +): DestinationsNavigator = DestinationsNavController( + navController = testNavController, + isCurrentBackStackEntryResumed = isCurrentBackStackEntryResumed +) \ No newline at end of file