class MotionSceneScope


Scope used by the MotionScene DSL.

 

Define new ConstraintSets and Transitions within this scope using constraintSet and transition respectively.

Alternatively, you may add existing objects to this scope using addConstraintSet and addTransition.

 

The defaultTransition should always be set. It defines the initial state of the layout and works as a fallback for undefined from -> to transitions.

Summary

Public functions

ConstraintSetRef
addConstraintSet(constraintSet: ConstraintSet, name: String?)

Adds an existing ConstraintSet object to the scope of this MotionScene.

Unit
addTransition(transition: Transition, name: String?)

Adds an existing Transition object to the scope of this MotionScene.

ConstraintSetRef
constraintSet(
    name: String?,
    extendConstraintSet: ConstraintSetRef?,
    constraintSetContent: ConstraintSetScope.() -> Unit
)

Creates a ConstraintSet that extends the changes applied by extendConstraintSet (if not null).

ConstrainedLayoutReference

Creates one ConstrainedLayoutReference corresponding to the ConstraintLayout element with id.

MotionSceneScope.ConstrainedLayoutReferences
createRefsFor(vararg ids: Any)

Convenient way to create multiple ConstrainedLayoutReference with one statement, the ids provided should match Composables within ConstraintLayout using androidx.compose.ui.Modifier.layoutId.

Unit

Declare a custom Color value addressed by name.

Unit

Sets the custom Color value at the frame of the current KeyAttributeScope.

Unit

Declare a custom Dp value addressed by name.

Unit

Sets the custom Dp value at the frame of the current KeyAttributeScope.

Unit

Declare a custom Float value addressed by name.

Unit

Sets the custom Float value at the frame of the current KeyAttributeScope.

Unit

Declare a custom TextUnit value addressed by name.

Unit

Sets the custom TextUnit value at the frame of the current KeyAttributeScope.

Unit

Declare a custom Int value addressed by name.

Unit

Sets the custom Int value at the frame of the current KeyAttributeScope.

Unit
defaultTransition(
    from: ConstraintSetRef,
    to: ConstraintSetRef,
    transitionContent: TransitionScope.() -> Unit
)

Defines the default Transition, where the from and tos will be the initial start and end states of the layout.

Unit
transition(
    from: ConstraintSetRef,
    to: ConstraintSetRef,
    name: String?,
    transitionContent: TransitionScope.() -> Unit
)

Adds a Transition defined by transitionContent.

Public properties

Float

Custom staggered weight.

Public functions

addConstraintSet

Added in 1.1.0-alpha13
fun addConstraintSet(constraintSet: ConstraintSet, name: String? = null): ConstraintSetRef

Adds an existing ConstraintSet object to the scope of this MotionScene. A name may be provided and it can be used on MotionLayout calls that request a ConstraintSet name.

Returns a ConstraintSetRef object representing the added constraintSet, which may be used as a parameter of transition.

addTransition

Added in 1.1.0-alpha13
fun addTransition(transition: Transition, name: String? = null): Unit

Adds an existing Transition object to the scope of this MotionScene. A name may be provided and it can be used on MotionLayout calls that request a Transition name.

The ConstraintSets referenced by the transition must match the name of a ConstraintSet added within this scope.

constraintSet

Added in 1.1.0-alpha13
fun constraintSet(
    name: String? = null,
    extendConstraintSet: ConstraintSetRef? = null,
    constraintSetContent: ConstraintSetScope.() -> Unit
): ConstraintSetRef

Creates a ConstraintSet that extends the changes applied by extendConstraintSet (if not null).

A name may be provided and it can be used on MotionLayout calls that request a ConstraintSet name.

Returns a ConstraintSetRef object representing this ConstraintSet, which may be used as a parameter of transition.

createRefFor

Added in 1.1.0-alpha13
fun createRefFor(id: Any): ConstrainedLayoutReference

Creates one ConstrainedLayoutReference corresponding to the ConstraintLayout element with id.

createRefsFor

Added in 1.1.0-alpha13
fun createRefsFor(vararg ids: Any): MotionSceneScope.ConstrainedLayoutReferences

Convenient way to create multiple ConstrainedLayoutReference with one statement, the ids provided should match Composables within ConstraintLayout using androidx.compose.ui.Modifier.layoutId.

Example:

val (box, text, button) = createRefsFor("box", "text", "button")

Note that the number of ids should match the number of variables assigned.

 

To create a singular ConstrainedLayoutReference see createRefFor.

fun ConstrainScope.customColor(name: String, value: Color): Unit

Declare a custom Color value addressed by name.

fun KeyAttributeScope.customColor(name: String, value: Color): Unit

Sets the custom Color value at the frame of the current KeyAttributeScope.

fun ConstrainScope.customDistance(name: String, value: Dp): Unit

Declare a custom Dp value addressed by name.

fun KeyAttributeScope.customDistance(name: String, value: Dp): Unit

Sets the custom Dp value at the frame of the current KeyAttributeScope.

fun ConstrainScope.customFloat(name: String, value: Float): Unit

Declare a custom Float value addressed by name.

fun KeyAttributeScope.customFloat(name: String, value: Float): Unit

Sets the custom Float value at the frame of the current KeyAttributeScope.

fun ConstrainScope.customFontSize(name: String, value: TextUnit): Unit

Declare a custom TextUnit value addressed by name.

fun KeyAttributeScope.customFontSize(name: String, value: TextUnit): Unit

Sets the custom TextUnit value at the frame of the current KeyAttributeScope.

fun ConstrainScope.customInt(name: String, value: Int): Unit

Declare a custom Int value addressed by name.

fun KeyAttributeScope.customInt(name: String, value: Int): Unit

Sets the custom Int value at the frame of the current KeyAttributeScope.

defaultTransition

Added in 1.1.0-alpha13
fun defaultTransition(
    from: ConstraintSetRef,
    to: ConstraintSetRef,
    transitionContent: TransitionScope.() -> Unit = { }
): Unit

Defines the default Transition, where the from and tos will be the initial start and end states of the layout.

The default Transition will also be applied when the combination of from and to ConstraintSets was not defined by a transition call.

This Transition is required to initialize MotionLayout.

transition

Added in 1.1.0-alpha13
fun transition(
    from: ConstraintSetRef,
    to: ConstraintSetRef,
    name: String? = null,
    transitionContent: TransitionScope.() -> Unit
): Unit

Adds a Transition defined by transitionContent. A name may be provided and it can be used on MotionLayout calls that request a Transition name.

Where from and to are the ConstraintSets handled by it.

Public properties

var ConstrainScope.staggeredWeightFloat

Custom staggered weight. When set, MotionLayout will use these values instead of the default way of calculating the weight, ignoring those with a Float.NaN value.

 

The value is Float.NaN by default. Note that when all widgets are set to Float.NaN, MotionLayout will use the default way of calculating the weight.

See also
maxStaggerDelay