Skip to content

Commit

Permalink
Added TestDestinationsNavigator API.
Browse files Browse the repository at this point in the history
  • Loading branch information
raamcosta committed Mar 9, 2024
1 parent 6ae5ef6 commit 867f492
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
)

0 comments on commit 867f492

Please sign in to comment.