Google is committed to advancing racial equity for Black communities. See how.

SelectionRegistrar

interface SelectionRegistrar
androidx.compose.ui.selection.SelectionRegistrar

An interface allowing a composable to subscribe and unsubscribe to selection changes.

Summary

Public methods
abstract Unit

When the Global Position of a subscribed Selectable changes, this method is called.

abstract Unit

Call this method to notify the SelectionContainer that the content of the passed selectable has been changed.

abstract Unit
notifySelectionUpdate(layoutCoordinates: LayoutCoordinates, startPosition: Offset, endPosition: Offset)

Call this method to notify the SelectionContainer that the selection has been updated.

abstract Unit

Call this method to notify the SelectionContainer that the selection update has stopped.

abstract Unit
notifySelectionUpdateStart(layoutCoordinates: LayoutCoordinates, startPosition: Offset)

Call this method to notify the SelectionContainer that the selection has been initiated.

abstract Selectable
subscribe(selectable: Selectable)

Subscribe to SelectionContainer selection changes.

abstract Unit
unsubscribe(selectable: Selectable)

Unsubscribe from SelectionContainer selection changes.

Public methods

notifyPositionChange

abstract fun notifyPositionChange(): Unit

When the Global Position of a subscribed Selectable changes, this method is called.

notifySelectableChange

abstract fun notifySelectableChange(selectable: Selectable): Unit

Call this method to notify the SelectionContainer that the content of the passed selectable has been changed.

Parameters
selectable: Selectable the selectable whose the content has been updated.

notifySelectionUpdate

abstract fun notifySelectionUpdate(
    layoutCoordinates: LayoutCoordinates,
    startPosition: Offset,
    endPosition: Offset
): Unit

Call this method to notify the SelectionContainer that the selection has been updated. The caller of this method should make sure that notifySelectionUpdateStart is always called once before calling this function. And notifySelectionUpdateEnd is always called once after the all updates finished.

Parameters
layoutCoordinates: LayoutCoordinates LayoutCoordinates of the Selectable.
startPosition: Offset coordinates of where the selection starts.
endPosition: Offset coordinates of where the selection ends.

notifySelectionUpdateEnd

abstract fun notifySelectionUpdateEnd(): Unit

Call this method to notify the SelectionContainer that the selection update has stopped.

notifySelectionUpdateStart

abstract fun notifySelectionUpdateStart(
    layoutCoordinates: LayoutCoordinates,
    startPosition: Offset
): Unit

Call this method to notify the SelectionContainer that the selection has been initiated. Depends on the input, notifySelectionUpdate may be called repeatedly after notifySelectionUpdateStart is called. And notifySelectionUpdateEnd should always be called after selection finished. For example:

  1. User long pressed the text and then release. notifySelectionUpdateStart should be called followed by notifySelectionUpdateEnd being called once.
  2. User long pressed the text and then drag a distance and then release. notifySelectionUpdateStart should be called first after the user long press, and then notifySelectionUpdate is called several times reporting the updates, in the end notifySelectionUpdateEnd is called to finish the selection.
Parameters
layoutCoordinates: LayoutCoordinates LayoutCoordinates of the Selectable.
startPosition: Offset coordinates of where the selection is initiated.

subscribe

abstract fun subscribe(selectable: Selectable): Selectable

Subscribe to SelectionContainer selection changes.

unsubscribe

abstract fun unsubscribe(selectable: Selectable): Unit

Unsubscribe from SelectionContainer selection changes.