DraggableAnchors

Interface

Common
interface DraggableAnchors<T>

Structure that represents the anchors of a AnchoredDraggableState.

See the DraggableAnchors factory method to construct drag anchors using a default implementation. This structure does not make any guarantees about ordering of the anchors.

Properties

Common
val size: Int

The number of anchors

Functions

fun positionOf(anchor: T): Float

Get the anchor position for an associated anchor

Parameters

anchorThe value to look up

Returns

The position of the anchor, or Float.NaN if the anchor does not exist
fun hasPositionFor(anchor: T): Boolean

Whether there is an anchor position associated with the anchor

Parameters

anchorThe value to look up

Returns

true if there is an anchor for this value, false if there is no anchor for this value
fun closestAnchor(position: Float): T?

Find the closest anchor value to the position.

Parameters

positionThe position to start searching from

Returns

The closest anchor or null if the anchors are empty
fun closestAnchor(position: Float, searchUpwards: Boolean): T?

Find the closest anchor value to the position, in the specified direction.

Parameters

positionThe position to start searching from
searchUpwardsWhether to search upwards from the current position or downwards

Returns

The closest anchor or null if the anchors are empty
fun minPosition(): Float

The smallest anchor position, or Float.NEGATIVE_INFINITY if the anchors are empty.

fun maxPosition(): Float

The biggest anchor position, or Float.POSITIVE_INFINITY if the anchors are empty.

fun anchorAt(index: Int): T?

Get the anchor key at the specified index, or null if the index is out of bounds.

fun positionAt(index: Int): Float

Get the anchor position at the specified index, or Float.NaN if the index is out of bounds.