The second Android 11 Developer Preview is now available, test it out and share your feedback.

androidx.ui.foundation.gestures

Classes

DragDirection

Draggable Direction specifies the direction in which you can drag an draggable or scrollable.

ScrollableState

State of the scrollable composable.

Top-level functions summary

ScrollableState
ScrollableState(onScrollDeltaConsumptionRequested: (Float) -> Float)

Create ScrollableState for scrollable with default FlingConfig and AnimationClockObservable

Modifier
draggable(dragDirection: DragDirection, onDragStarted: (startedPosition: PxPosition) -> Unit = {}, onDragStopped: (velocity: Float) -> Unit = {}, enabled: Boolean = true, startDragImmediately: Boolean = false, onDragDeltaConsumptionRequested: (Float) -> Float)

High level gesture modifier that provides declarative API for setting up drag within one layout node

Modifier
scrollable(dragDirection: DragDirection, scrollableState: ScrollableState, onScrollStarted: (startedPosition: PxPosition) -> Unit = {}, onScrollStopped: (velocity: Float) -> Unit = {}, enabled: Boolean = true)

High-level gesture modifier that provides scroll functionality.

Top-level functions

ScrollableState

@Composable fun ScrollableState(onScrollDeltaConsumptionRequested: (Float) -> Float): ScrollableState

Create ScrollableState for scrollable with default FlingConfig and AnimationClockObservable

Parameters
onScrollDeltaConsumptionRequested: (Float) -> Float callback to be invoked when scrollable drag/fling/smooth scrolling occurs. Users must update their state in this lambda and return amount of delta consumed

draggable

@Composable fun draggable(
    dragDirection: DragDirection,
    onDragStarted: (startedPosition: PxPosition) -> Unit = {},
    onDragStopped: (velocity: Float) -> Unit = {},
    enabled: Boolean = true,
    startDragImmediately: Boolean = false,
    onDragDeltaConsumptionRequested: (Float) -> Float
): Modifier

High level gesture modifier that provides declarative API for setting up drag within one layout node

The common usecase for this component is when you need to be able to drag something inside the component on the screen and represent this state via one float value

If you need to control the whole dragging flow, consider using DragGestureDetector instead.

If you need to achieve scroll/fling behavior, consider using scrollable.


//Unresolved: androidx.ui.foundation.samples.DraggableSample
By using AnimatedFloat as state you can achieve fling behaviour by calling fling on it

//Unresolved: androidx.ui.foundation.samples.AnchoredDraggableSample
Parameters
dragDirection: DragDirection direction in which drag should be happening
onDragDeltaConsumptionRequested: (Float) -> Float callback to be invoked when drag occurs. Users must update their state in this lambda and return amount of delta consumed
onDragStarted: (startedPosition: PxPosition) -> Unit = {} callback that will be invoked when drag has been started after touch slop has been passed, with starting position provided
onDragStopped: (velocity: Float) -> Unit = {} callback that will be invoked when drag stops, with velocity provided
enabled: Boolean = true whether or not drag is enabled
startDragImmediately: Boolean = false when set to true, draggable will start dragging immediately and prevent other gesture detectors from reacting to "down" events (in order to block composed press-based gestures). This is intended to allow end users to "catch" an animating widget by pressing on it. It's useful to set it when value you're dragging is settling / animating.

scrollable

@Composable fun scrollable(
    dragDirection: DragDirection,
    scrollableState: ScrollableState,
    onScrollStarted: (startedPosition: PxPosition) -> Unit = {},
    onScrollStopped: (velocity: Float) -> Unit = {},
    enabled: Boolean = true
): Modifier

High-level gesture modifier that provides scroll functionality.

When you need to be able to scroll with fling support and smooth scrolling inside composable, consider using this modifier.

Although ScrollableState is required for this composable to be able to work correctly, users of this composable should own, update and reflect their own state. When constructing ScrollableState, you need to pass ScrollableState.onScrollDeltaConsumptionRequested lambda, which will be invoked every time with the delta when scroll is happening (by gesture input, my smooth scrolling or flinging). In this lambda you can change your own state and reflect it on UI. Amount of scrolling delta consumed must be returned from this lambda.


//Unresolved: androidx.ui.foundation.samples.ScrollableSample
Parameters
dragDirection: DragDirection axis to scroll alongside
scrollableState: ScrollableState ScrollableState object that holds internal state of this Scrollable, invokes ScrollableState.onScrollDeltaConsumptionRequested callback and provides smooth scrolling capabilities
onScrollStarted: (startedPosition: PxPosition) -> Unit = {} callback to be invoked when scroll has started from the certain position on the screen
onScrollStopped: (velocity: Float) -> Unit = {} callback to be invoked when scroll stops with amount of velocity unconsumed provided
enabled: Boolean = true whether of not scrolling in enabled