TestNavigationEventCallback


public final class TestNavigationEventCallback<T extends NavigationEventInfo> extends NavigationEventCallback


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 extends NavigationEventInfo>

The type of NavigationEventInfo this callback handles.

Summary

Public constructors

<T extends NavigationEventInfo> TestNavigationEventCallback(
    @NonNull T currentInfo,
    T previousInfo,
    boolean isEnabled,
    @NonNull Function2<@NonNull TestNavigationEventCallback<@NonNull T>, @NonNull NavigationEventUnit> onEventStarted,
    @NonNull Function2<@NonNull TestNavigationEventCallback<@NonNull T>, @NonNull NavigationEventUnit> onEventProgressed,
    @NonNull Function1<@NonNull TestNavigationEventCallback<@NonNull T>, Unit> onEventCancelled,
    @NonNull Function1<@NonNull TestNavigationEventCallback<@NonNull T>, Unit> onEventCompleted
)

Public methods

final int

The number of times onEventCancelled has been invoked.

final int

The number of times onEventCompleted has been invoked.

final @NonNull List<@NonNull NavigationEvent>

A List of all events received by the onEventProgressed callback.

final int

The number of times onEventProgressed has been invoked.

final @NonNull List<@NonNull NavigationEvent>

A List of all events received by the onEventStarted callback.

final int

The number of times onEventStarted has been invoked.

Protected methods

void

Override this to handle the cancellation of a navigation event.

void

Override this to handle the completion of a navigation event.

void

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

void

Override this to handle the beginning of a navigation event.

Inherited methods

From androidx.navigationevent.NavigationEventCallback
final boolean

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

final void

Removes this callback from the NavigationEventDispatcher it is registered with.

final void
setEnabled(boolean isEnabled)

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

final void
setInfo(@NonNull T currentInfo, T previousInfo)

Updates the current and previous navigation information for this callback.

Public constructors

TestNavigationEventCallback

public <T extends NavigationEventInfo> TestNavigationEventCallback(
    @NonNull T currentInfo,
    T previousInfo,
    boolean isEnabled,
    @NonNull Function2<@NonNull TestNavigationEventCallback<@NonNull T>, @NonNull NavigationEventUnit> onEventStarted,
    @NonNull Function2<@NonNull TestNavigationEventCallback<@NonNull T>, @NonNull NavigationEventUnit> onEventProgressed,
    @NonNull Function1<@NonNull TestNavigationEventCallback<@NonNull T>, Unit> onEventCancelled,
    @NonNull Function1<@NonNull TestNavigationEventCallback<@NonNull T>, Unit> onEventCompleted
)
Parameters
<T extends NavigationEventInfo>

The type of NavigationEventInfo this callback handles.

@NonNull T currentInfo

The initial current navigation information for the callback.

T previousInfo

The initial previous navigation information. Defaults to null.

boolean isEnabled

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

@NonNull Function2<@NonNull TestNavigationEventCallback<@NonNull T>, @NonNull NavigationEventUnit> onEventStarted

An optional lambda to execute when onEventStarted is called.

@NonNull Function2<@NonNull TestNavigationEventCallback<@NonNull T>, @NonNull NavigationEventUnit> onEventProgressed

An optional lambda to execute when onEventProgressed is called.

@NonNull Function1<@NonNull TestNavigationEventCallback<@NonNull T>, Unit> onEventCancelled

An optional lambda to execute when onEventCancelled is called.

@NonNull Function1<@NonNull TestNavigationEventCallback<@NonNull T>, Unit> onEventCompleted

An optional lambda to execute when onEventCompleted is called.

Public methods

getCancelledInvocations

Added in 1.0.0-alpha07
public final int getCancelledInvocations()

The number of times onEventCancelled has been invoked.

getCompletedInvocations

Added in 1.0.0-alpha07
public final int getCompletedInvocations()

The number of times onEventCompleted has been invoked.

getProgressedEvents

Added in 1.0.0-alpha07
public final @NonNull List<@NonNull NavigationEventgetProgressedEvents()

A List of all events received by the onEventProgressed callback.

getProgressedInvocations

Added in 1.0.0-alpha07
public final int getProgressedInvocations()

The number of times onEventProgressed has been invoked.

getStartedEvents

Added in 1.0.0-alpha07
public final @NonNull List<@NonNull NavigationEventgetStartedEvents()

A List of all events received by the onEventStarted callback.

getStartedInvocations

Added in 1.0.0-alpha07
public final int getStartedInvocations()

The number of times onEventStarted has been invoked.

Protected methods

onEventCancelled

protected void onEventCancelled()

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

Added in 1.0.0-alpha07
protected void onEventCompleted()

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 void onEventProgressed(@NonNull NavigationEvent event)

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
@NonNull NavigationEvent event

The NavigationEvent containing progress information.

onEventStarted

protected void onEventStarted(@NonNull NavigationEvent event)

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
@NonNull NavigationEvent event

The NavigationEvent that triggered this callback.