TestNavigationEventHandler



A test implementation of NavigationEventHandler that records received events and invocation counts.

This class is primarily used in tests to verify that specific navigation event callbacks are triggered as expected. It captures the NavigationEvent objects and counts how many times each callback is fired.

Parameters
<T : NavigationEventInfo>

The NavigationEventInfo type this callback handles.

Summary

Public constructors

<T : NavigationEventInfo> TestNavigationEventHandler(
    currentInfo: T,
    backInfo: List<T>,
    forwardInfo: List<T>,
    isForwardEnabled: Boolean,
    onForwardStarted: TestNavigationEventHandler<T>.(event: NavigationEvent) -> Unit,
    onForwardProgressed: TestNavigationEventHandler<T>.(event: NavigationEvent) -> Unit,
    onForwardCancelled: TestNavigationEventHandler<T>.() -> Unit,
    onForwardCompleted: TestNavigationEventHandler<T>.() -> Unit,
    isBackEnabled: Boolean,
    onBackStarted: TestNavigationEventHandler<T>.(event: NavigationEvent) -> Unit,
    onBackProgressed: TestNavigationEventHandler<T>.(event: NavigationEvent) -> Unit,
    onBackCancelled: TestNavigationEventHandler<T>.() -> Unit,
    onBackCompleted: TestNavigationEventHandler<T>.() -> Unit
)
Cmn

Protected functions

open Unit

Override this to handle the cancellation of a back navigation event.

Cmn
open Unit

Override this to handle the completion of a back navigation event.

Cmn
open Unit

Override this to handle the progress of an ongoing back navigation event.

Cmn
open Unit

Override this to handle the beginning of a back navigation event.

Cmn
open Unit

Override this to handle the cancellation of a forward navigation event.

Cmn
open Unit

Override this to handle the completion of a forward navigation event.

Cmn
open Unit

Override this to handle the progress of an ongoing forward navigation event.

Cmn
open Unit

Override this to handle the beginning of a forward navigation event.

Cmn

Public properties

Int

Number of times onBackCancelled has been invoked.

Cmn
Int

Number of times onBackCompleted has been invoked.

Cmn
List<NavigationEvent>

All events received by onBackProgressed.

Cmn
Int

Number of times onBackProgressed has been invoked.

Cmn
List<NavigationEvent>

All events received by onBackStarted.

Cmn
Int

Number of times onBackStarted has been invoked.

Cmn
Int

Number of times onForwardCancelled has been invoked.

Cmn
Int

Number of times onForwardCompleted has been invoked.

Cmn
List<NavigationEvent>

All events received by onForwardProgressed.

Cmn
Int

Number of times onForwardProgressed has been invoked.

Cmn
List<NavigationEvent>

All events received by onForwardStarted.

Cmn
Int

Number of times onForwardStarted has been invoked.

Cmn

Inherited functions

From androidx.navigationevent.NavigationEventHandler
Unit

Removes this handler from the NavigationEventDispatcher it is registered with.

Cmn
Unit
setInfo(currentInfo: T, backInfo: List<T>, forwardInfo: List<T>)

Sets the directional navigation context for this handler.

Cmn

Inherited properties

From androidx.navigationevent.NavigationEventHandler
List<T>

Contextual information describing the application's back state for this handler.

Cmn
T

The contextual information representing the active destination for this handler.

Cmn
List<T>

Contextual information describing the application's forward state for this handler.

Cmn
Boolean

Controls whether this handler is active and should be considered for back event dispatching.

Cmn
Boolean

Controls whether this handler is active and should be considered for forward event dispatching.

Cmn
NavigationEventTransitionState

The current transition state of this specific handler (e.g., Idle or InProgress).

Cmn

Public constructors

TestNavigationEventHandler

<T : NavigationEventInfo> TestNavigationEventHandler(
    currentInfo: T,
    backInfo: List<T> = emptyList(),
    forwardInfo: List<T> = emptyList(),
    isForwardEnabled: Boolean = true,
    onForwardStarted: TestNavigationEventHandler<T>.(event: NavigationEvent) -> Unit = {},
    onForwardProgressed: TestNavigationEventHandler<T>.(event: NavigationEvent) -> Unit = {},
    onForwardCancelled: TestNavigationEventHandler<T>.() -> Unit = {},
    onForwardCompleted: TestNavigationEventHandler<T>.() -> Unit = {},
    isBackEnabled: Boolean = true,
    onBackStarted: TestNavigationEventHandler<T>.(event: NavigationEvent) -> Unit = {},
    onBackProgressed: TestNavigationEventHandler<T>.(event: NavigationEvent) -> Unit = {},
    onBackCancelled: TestNavigationEventHandler<T>.() -> Unit = {},
    onBackCompleted: TestNavigationEventHandler<T>.() -> Unit = {}
)
Parameters
<T : NavigationEventInfo>

The NavigationEventInfo type this callback handles.

currentInfo: T

Initial current navigation info.

backInfo: List<T> = emptyList()

Initial back stack info list. Defaults to empty.

forwardInfo: List<T> = emptyList()

Initial forward stack info list. Defaults to empty.

isForwardEnabled: Boolean = true

Determines if forward callbacks should process events. Defaults to true.

onForwardStarted: TestNavigationEventHandler<T>.(event: NavigationEvent) -> Unit = {}

Optional lambda to execute when onForwardStarted is called.

onForwardProgressed: TestNavigationEventHandler<T>.(event: NavigationEvent) -> Unit = {}

Optional lambda to execute when onForwardProgressed is called.

onForwardCancelled: TestNavigationEventHandler<T>.() -> Unit = {}

Optional lambda to execute when onForwardCancelled is called.

onForwardCompleted: TestNavigationEventHandler<T>.() -> Unit = {}

Optional lambda to execute when onForwardCompleted is called.

isBackEnabled: Boolean = true

Determines if back callbacks should process events. Defaults to true.

onBackStarted: TestNavigationEventHandler<T>.(event: NavigationEvent) -> Unit = {}

Optional lambda to execute when onBackStarted is called.

onBackProgressed: TestNavigationEventHandler<T>.(event: NavigationEvent) -> Unit = {}

Optional lambda to execute when onBackProgressed is called.

onBackCancelled: TestNavigationEventHandler<T>.() -> Unit = {}

Optional lambda to execute when onBackCancelled is called.

onBackCompleted: TestNavigationEventHandler<T>.() -> Unit = {}

Optional lambda to execute when onBackCompleted is called.

Protected functions

onBackCancelled

protected open fun onBackCancelled(): Unit

Override this to handle the cancellation of a back navigation event.

This is called when the user cancels the navigation action, signaling that the UI should return to its original state.

onBackCompleted

protected open fun onBackCompleted(): Unit

Override this to handle the completion of a back navigation event.

This is called when the user commits to the back navigation action, signaling that the navigation should be finalized.

The default implementation throws an UnsupportedOperationException. Any handler that can be completed must override this method to handle the navigation.

onBackProgressed

protected open fun onBackProgressed(event: NavigationEvent): Unit

Override this to handle the progress of an ongoing back navigation event.

This is called repeatedly during a gesture-driven back navigation to update the UI in real-time based on the user's input.

Parameters
event: NavigationEvent

The NavigationEvent containing progress information.

onBackStarted

protected open fun onBackStarted(event: NavigationEvent): Unit

Override this to handle the beginning of a back navigation event.

This is called when a user action initiates a back navigation. It's the ideal place to prepare UI elements for a transition.

Parameters
event: NavigationEvent

The NavigationEvent that triggered this handler.

onForwardCancelled

protected open fun onForwardCancelled(): Unit

Override this to handle the cancellation of a forward navigation event.

This is called when the user cancels the navigation action, signaling that the UI should return to its original state.

onForwardCompleted

protected open fun onForwardCompleted(): Unit

Override this to handle the completion of a forward navigation event.

This is called when the user commits to the forward navigation action, signaling that the navigation should be finalized.

The default implementation throws an UnsupportedOperationException. Any handler that can be completed must override this method to handle the navigation.

onForwardProgressed

protected open fun onForwardProgressed(event: NavigationEvent): Unit

Override this to handle the progress of an ongoing forward navigation event.

This is called repeatedly during a gesture-driven forward navigation to update the UI in real-time based on the user's input.

Parameters
event: NavigationEvent

The NavigationEvent containing progress information.

onForwardStarted

protected open fun onForwardStarted(event: NavigationEvent): Unit

Override this to handle the beginning of a forward navigation event.

This is called when a user action initiates a forward navigation. It's the ideal place to prepare UI elements for a transition.

Parameters
event: NavigationEvent

The NavigationEvent that triggered this handler.

Public properties

onBackCancelledInvocations

val onBackCancelledInvocationsInt

Number of times onBackCancelled has been invoked.

onBackCompletedInvocations

val onBackCompletedInvocationsInt

Number of times onBackCompleted has been invoked.

onBackProgressedEvents

val onBackProgressedEventsList<NavigationEvent>

All events received by onBackProgressed.

onBackProgressedInvocations

val onBackProgressedInvocationsInt

Number of times onBackProgressed has been invoked.

onBackStartedEvents

val onBackStartedEventsList<NavigationEvent>

All events received by onBackStarted.

onBackStartedInvocations

val onBackStartedInvocationsInt

Number of times onBackStarted has been invoked.

onForwardCancelledInvocations

val onForwardCancelledInvocationsInt

Number of times onForwardCancelled has been invoked.

onForwardCompletedInvocations

val onForwardCompletedInvocationsInt

Number of times onForwardCompleted has been invoked.

onForwardProgressedEvents

val onForwardProgressedEventsList<NavigationEvent>

All events received by onForwardProgressed.

onForwardProgressedInvocations

val onForwardProgressedInvocationsInt

Number of times onForwardProgressed has been invoked.

onForwardStartedEvents

val onForwardStartedEventsList<NavigationEvent>

All events received by onForwardStarted.

onForwardStartedInvocations

val onForwardStartedInvocationsInt

Number of times onForwardStarted has been invoked.