TestNavigationEventCallback



A test implementation of NavigationEventCallback 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 type of NavigationEventInfo this callback handles.

Summary

Public constructors

<T : NavigationEventInfo> TestNavigationEventCallback(
    currentInfo: T,
    previousInfo: T?,
    isEnabled: Boolean,
    onEventStarted: TestNavigationEventCallback<T>.(event: NavigationEvent) -> Unit,
    onEventProgressed: TestNavigationEventCallback<T>.(event: NavigationEvent) -> Unit,
    onEventCancelled: TestNavigationEventCallback<T>.() -> Unit,
    onEventCompleted: TestNavigationEventCallback<T>.() -> Unit
)
Cmn

Protected functions

open Unit

Override this to handle the cancellation of a navigation event.

Cmn
open Unit

Override this to handle the completion of a navigation event.

Cmn
open Unit

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

Cmn
open Unit

Override this to handle the beginning of a navigation event.

Cmn

Public properties

Int

The number of times onEventCancelled has been invoked.

Cmn
Int

The number of times onEventCompleted has been invoked.

Cmn
List<NavigationEvent>

A List of all events received by the onEventProgressed callback.

Cmn
Int

The number of times onEventProgressed has been invoked.

Cmn
List<NavigationEvent>

A List of all events received by the onEventStarted callback.

Cmn
Int

The number of times onEventStarted has been invoked.

Cmn

Inherited functions

From androidx.navigationevent.NavigationEventCallback
Unit

Removes this callback from the NavigationEventDispatcher it is registered with.

Cmn
Unit
setInfo(currentInfo: T, previousInfo: T?)

Updates the current and previous navigation information for this callback.

Cmn

Inherited properties

From androidx.navigationevent.NavigationEventCallback
Boolean

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

Cmn

Public constructors

TestNavigationEventCallback

<T : NavigationEventInfo> TestNavigationEventCallback(
    currentInfo: T,
    previousInfo: T? = null,
    isEnabled: Boolean = true,
    onEventStarted: TestNavigationEventCallback<T>.(event: NavigationEvent) -> Unit = {},
    onEventProgressed: TestNavigationEventCallback<T>.(event: NavigationEvent) -> Unit = {},
    onEventCancelled: TestNavigationEventCallback<T>.() -> Unit = {},
    onEventCompleted: TestNavigationEventCallback<T>.() -> Unit = {}
)
Parameters
<T : NavigationEventInfo>

The type of NavigationEventInfo this callback handles.

currentInfo: T

The initial current navigation information for the callback.

previousInfo: T? = null

The initial previous navigation information. Defaults to null.

isEnabled: Boolean = true

Determines if the callback should process events. Defaults to true.

onEventStarted: TestNavigationEventCallback<T>.(event: NavigationEvent) -> Unit = {}

An optional lambda to execute when onEventStarted is called.

onEventProgressed: TestNavigationEventCallback<T>.(event: NavigationEvent) -> Unit = {}

An optional lambda to execute when onEventProgressed is called.

onEventCancelled: TestNavigationEventCallback<T>.() -> Unit = {}

An optional lambda to execute when onEventCancelled is called.

onEventCompleted: TestNavigationEventCallback<T>.() -> Unit = {}

An optional lambda to execute when onEventCompleted is called.

Protected functions

onEventCancelled

protected open fun onEventCancelled(): Unit

Override this to handle the cancellation of a navigation event.

This is called when the user cancels the navigation action (e.g., by returning their finger to the edge of the screen), signaling that the UI should return to its original state.

onEventCompleted

protected open fun onEventCompleted(): Unit

Override this to handle the completion of a navigation event.

This is called when the user commits to the navigation action (e.g., by lifting their finger at the end of a swipe), signaling that the navigation should be finalized.

onEventProgressed

protected open fun onEventProgressed(event: NavigationEvent): Unit

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

This is called repeatedly during a gesture-driven navigation (e.g., a predictive back swipe) to update the UI in real-time based on the user's input.

Parameters
event: NavigationEvent

The NavigationEvent containing progress information.

onEventStarted

protected open fun onEventStarted(event: NavigationEvent): Unit

Override this to handle the beginning of a navigation event.

This is called when a user action, such as a swipe gesture, initiates a navigation. It's the ideal place to prepare UI elements for a transition.

Parameters
event: NavigationEvent

The NavigationEvent that triggered this callback.

Public properties

cancelledInvocations

val cancelledInvocationsInt

The number of times onEventCancelled has been invoked.

completedInvocations

val completedInvocationsInt

The number of times onEventCompleted has been invoked.

progressedEvents

val progressedEventsList<NavigationEvent>

A List of all events received by the onEventProgressed callback.

progressedInvocations

val progressedInvocationsInt

The number of times onEventProgressed has been invoked.

startedEvents

val startedEventsList<NavigationEvent>

A List of all events received by the onEventStarted callback.

startedInvocations

val startedInvocationsInt

The number of times onEventStarted has been invoked.