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

TransformableState

public interface TransformableState


State of transformable. Allows for a granular control of how different gesture transformations are consumed by the user as well as to write custom transformation methods using transform suspend function.

Summary

Public methods

abstract boolean

Whether this TransformableState is currently transforming by gesture or programmatically or not.

abstract void
transform(
    @NonNull MutatePriority transformPriority,
    @ExtensionFunctionType @NonNull SuspendFunction1<@NonNull TransformScopeUnit> block
)

Call this function to take control of transformations and gain the ability to send transform events via TransformScope.transformBy.

Extension functions

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

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

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

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

default final void
TransformableStateKt.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.

default final void
TransformableStateKt.panBy(
    @NonNull TransformableState receiver,
    @NonNull Offset offset
)

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

default final void
TransformableStateKt.rotateBy(
    @NonNull TransformableState receiver,
    float degrees
)

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

default final void

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

default final void
TransformableStateKt.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

isTransformInProgress

abstract boolean isTransformInProgress()

Whether this TransformableState is currently transforming by gesture or programmatically or not.

transform

abstract void transform(
    @NonNull MutatePriority transformPriority,
    @ExtensionFunctionType @NonNull SuspendFunction1<@NonNull TransformScopeUnit> block
)

Call this function to take control of transformations and gain the ability to send transform events via TransformScope.transformBy. All actions that change zoom, pan or rotation values must be performed within a transform block (even if they don't call any other methods on this object) in order to guarantee that mutual exclusion is enforced.

If transform is called from elsewhere with the transformPriority higher or equal to ongoing transform, ongoing transform will be canceled.

Extension functions

TransformableStateKt.animatePanBy

default final void TransformableStateKt.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

TransformableStateKt.animateRotateBy

default final void TransformableStateKt.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

TransformableStateKt.animateZoomBy

default final void TransformableStateKt.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

TransformableStateKt.panBy

default final void TransformableStateKt.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

TransformableStateKt.rotateBy

default final void TransformableStateKt.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

TransformableStateKt.stopTransformation

default final void TransformableStateKt.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

TransformableStateKt.zoomBy

default final void TransformableStateKt.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