{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

TransformableStateKt

public final class TransformableStateKt


Summary

Public methods

static final @NonNull TransformableState
TransformableState(
    @NonNull Function3<@NonNull Float, @NonNull Offset, @NonNull FloatUnit> onTransformation
)

Default implementation of TransformableState interface that contains necessary information about the ongoing transformations and provides smooth transformation capabilities.

static final void
animatePanBy(
    @NonNull TransformableState receiver,
    @NonNull Offset offset,
    @NonNull AnimationSpec<@NonNull Offset> animationSpec
)

Animate pan by offset Offset in pixels and suspend until its finished

static final void
animateRotateBy(
    @NonNull TransformableState receiver,
    float degrees,
    @NonNull AnimationSpec<@NonNull Float> animationSpec
)

Animate rotate by a ratio of degrees clockwise and suspend until its finished.

static final void
animateZoomBy(
    @NonNull TransformableState receiver,
    float zoomFactor,
    @NonNull AnimationSpec<@NonNull Float> animationSpec
)

Animate zoom by a ratio of zoomFactor over the current size and suspend until its finished.

static final void

Pan without animation by a offset Offset in pixels and suspend until it's set.

static final @NonNull TransformableState
@Composable
rememberTransformableState(
    @NonNull Function3<@NonNull Float, @NonNull Offset, @NonNull FloatUnit> onTransformation
)

Create and remember default implementation of TransformableState interface that contains necessary information about the ongoing transformations and provides smooth transformation capabilities.

static final void
rotateBy(@NonNull TransformableState receiver, float degrees)

Rotate without animation by a degrees degrees and suspend until it's set.

static final void
stopTransformation(
    @NonNull TransformableState receiver,
    @NonNull MutatePriority terminationPriority
)

Stop and suspend until any ongoing TransformableState.transform with priority terminationPriority or lower is terminated.

static final void
zoomBy(@NonNull TransformableState receiver, float zoomFactor)

Zoom without animation by a ratio of zoomFactor over the current size and suspend until it's set.

Public methods

TransformableState

public static final @NonNull TransformableState TransformableState(
    @NonNull Function3<@NonNull Float, @NonNull Offset, @NonNull FloatUnit> onTransformation
)

Default implementation of TransformableState interface that contains necessary information about the ongoing transformations and provides smooth transformation capabilities.

This is the simplest way to set up a transformable modifier. When constructing this TransformableState, you must provide a onTransformation lambda, which will be invoked whenever pan, zoom or rotation happens (by gesture input or any TransformableState.transform call) with the deltas from the previous event.

Parameters
@NonNull Function3<@NonNull Float, @NonNull Offset, @NonNull FloatUnit> onTransformation

callback invoked when transformation occurs. The callback receives the change from the previous event. It's relative scale multiplier for zoom, Offset in pixels for pan and degrees for rotation. Callers should update their state in this lambda.

animatePanBy

public static final void animatePanBy(
    @NonNull TransformableState receiver,
    @NonNull Offset offset,
    @NonNull AnimationSpec<@NonNull Offset> animationSpec
)

Animate pan by offset Offset in pixels and suspend until its finished

Parameters
@NonNull Offset offset

offset to pan, in pixels

@NonNull AnimationSpec<@NonNull Offset> animationSpec

AnimationSpec to be used for pan animation

animateRotateBy

public static final void animateRotateBy(
    @NonNull TransformableState receiver,
    float degrees,
    @NonNull AnimationSpec<@NonNull Float> animationSpec
)

Animate rotate by a ratio of degrees clockwise and suspend until its finished.

Parameters
float degrees

ratio over the current size by which to rotate, in degrees

@NonNull AnimationSpec<@NonNull Float> animationSpec

AnimationSpec to be used for animation

animateZoomBy

public static final void animateZoomBy(
    @NonNull TransformableState receiver,
    float zoomFactor,
    @NonNull AnimationSpec<@NonNull Float> animationSpec
)

Animate zoom by a ratio of zoomFactor over the current size and suspend until its finished.

Parameters
float zoomFactor

ratio over the current size by which to zoom. For example, if zoomFactor is 3f, zoom will be increased 3 fold from the current value.

@NonNull AnimationSpec<@NonNull Float> animationSpec

AnimationSpec to be used for animation

panBy

public static final void panBy(@NonNull TransformableState receiver, @NonNull Offset offset)

Pan without animation by a offset Offset in pixels and suspend until it's set.

Parameters
@NonNull Offset offset

offset in pixels by which to pan

rememberTransformableState

@Composable
public static final @NonNull TransformableState rememberTransformableState(
    @NonNull Function3<@NonNull Float, @NonNull Offset, @NonNull FloatUnit> onTransformation
)

Create and remember default implementation of TransformableState interface that contains necessary information about the ongoing transformations and provides smooth transformation capabilities.

This is the simplest way to set up a transformable modifier. When constructing this TransformableState, you must provide a onTransformation lambda, which will be invoked whenever pan, zoom or rotation happens (by gesture input or any TransformableState.transform call) with the deltas from the previous event.

Parameters
@NonNull Function3<@NonNull Float, @NonNull Offset, @NonNull FloatUnit> onTransformation

callback invoked when transformation occurs. The callback receives the change from the previous event. It's relative scale multiplier for zoom, Offset in pixels for pan and degrees for rotation. Callers should update their state in this lambda.

rotateBy

public static final void rotateBy(@NonNull TransformableState receiver, float degrees)

Rotate without animation by a degrees degrees and suspend until it's set.

Parameters
float degrees

degrees by which to rotate

stopTransformation

public static final void stopTransformation(
    @NonNull TransformableState receiver,
    @NonNull MutatePriority terminationPriority
)

Stop and suspend until any ongoing TransformableState.transform with priority terminationPriority or lower is terminated.

Parameters
@NonNull MutatePriority terminationPriority

transformation that runs with this priority or lower will be stopped

zoomBy

public static final void zoomBy(@NonNull TransformableState receiver, float zoomFactor)

Zoom without animation by a ratio of zoomFactor over the current size and suspend until it's set.

Parameters
float zoomFactor

ratio over the current size by which to zoom