NavigationEventCallback


public abstract class NavigationEventCallback<T extends NavigationEventInfo>

Known direct subclasses
TestNavigationEventCallback

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


Receives and handles NavigationEvents dispatched by a NavigationEventDispatcher.

This is the base class you should extend to create custom navigation event logic. Callbacks are added to a NavigationEventDispatcher and will only receive events when both the callback and its dispatcher are enabled.

Summary

Public constructors

<T extends NavigationEventInfo> NavigationEventCallback(boolean isEnabled)

Public methods

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.

Protected methods

void

Override this to handle the cancellation of a navigation event.

abstract 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.

Public constructors

public <T extends NavigationEventInfo> NavigationEventCallback(boolean isEnabled)
Parameters
boolean isEnabled

The initial enabled state for this callback. Defaults to true.

Public methods

isEnabled

Added in 1.0.0-alpha07
public final boolean isEnabled()

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

A callback's effective enabled state is hierarchical; it is directly influenced by the NavigationEventDispatcher it is registered with.

Getting the value:

  • This will return false if the associated dispatcher exists and its isEnabled state is false, regardless of the callback's own local setting. This provides a powerful mechanism to disable a whole group of callbacks at once by simply disabling their dispatcher.

  • Otherwise, it returns the callback's own locally stored state.

Setting the value:

  • This updates the local enabled state of the callback itself.

  • More importantly, it immediately notifies the dispatcher (if one is attached) that its list of enabled callbacks might have changed, prompting a re-evaluation. This ensures the system's state remains consistent and responsive to changes.

For a callback to be truly active, both its local isEnabled property and its dispatcher's isEnabled property must evaluate to true.

remove

Added in 1.0.0-alpha07
public final void remove()

Removes this callback from the NavigationEventDispatcher it is registered with. If the callback is not registered, this call does nothing.

setEnabled

Added in 1.0.0-alpha07
public final void setEnabled(boolean isEnabled)

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

A callback's effective enabled state is hierarchical; it is directly influenced by the NavigationEventDispatcher it is registered with.

Getting the value:

  • This will return false if the associated dispatcher exists and its isEnabled state is false, regardless of the callback's own local setting. This provides a powerful mechanism to disable a whole group of callbacks at once by simply disabling their dispatcher.

  • Otherwise, it returns the callback's own locally stored state.

Setting the value:

  • This updates the local enabled state of the callback itself.

  • More importantly, it immediately notifies the dispatcher (if one is attached) that its list of enabled callbacks might have changed, prompting a re-evaluation. This ensures the system's state remains consistent and responsive to changes.

For a callback to be truly active, both its local isEnabled property and its dispatcher's isEnabled property must evaluate to true.

setInfo

Added in 1.0.0-alpha07
public final void setInfo(@NonNull T currentInfo, T previousInfo)

Updates the current and previous navigation information for this callback.

This method updates the callback's local info and then notifies the central NavigationEventProcessor. The processor is responsible for deciding whether to update the global navigation state, ensuring that only the highest-priority callback can influence the state.

Parameters
@NonNull T currentInfo

The new navigation information to be set as the current state.

T previousInfo

The navigation information to be set as the previous state.

Protected methods

onEventCancelled

Added in 1.0.0-alpha07
@EmptySuper
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 abstract 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

Added in 1.0.0-alpha07
@EmptySuper
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

Added in 1.0.0-alpha07
@EmptySuper
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.