MotionSceneScope
@ExperimentalMotionApi
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
Nested types |
|---|
inner class MotionSceneScope.ConstrainedLayoutReferences |
Public functions |
|
|---|---|
ConstraintSetRef |
addConstraintSet(constraintSet: ConstraintSet, name: String?)Adds an existing |
Unit |
addTransition(transition: Transition, name: String?)Adds an existing |
ConstraintSetRef |
constraintSet(Creates a |
ConstrainedLayoutReference |
createRefFor(id: Any)Creates one |
MotionSceneScope.ConstrainedLayoutReferences |
createRefsFor(vararg ids: Any)Convenient way to create multiple |
Unit |
ConstrainScope.customColor(name: String, value: Color) |
Unit |
KeyAttributeScope.customColor(name: String, value: Color)Sets the custom Color |
Unit |
ConstrainScope.customDistance(name: String, value: Dp) |
Unit |
KeyAttributeScope.customDistance(name: String, value: Dp)Sets the custom Dp |
Unit |
ConstrainScope.customFloat(name: String, value: Float) |
Unit |
KeyAttributeScope.customFloat(name: String, value: Float)Sets the custom Float |
Unit |
ConstrainScope.customFontSize(name: String, value: TextUnit) |
Unit |
KeyAttributeScope.customFontSize(name: String, value: TextUnit)Sets the custom TextUnit |
Unit |
ConstrainScope.customInt(name: String, value: Int) |
Unit |
KeyAttributeScope.customInt(name: String, value: Int)Sets the custom Int |
Unit |
defaultTransition(Defines the default |
Unit |
transition(Adds a |
Public properties |
|
|---|---|
Float |
Custom staggered weight. |
Public functions
addConstraintSet
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
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.
| See also | |
|---|---|
constraintSet |
|
addConstraintSet |
constraintSet
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
fun createRefFor(id: Any): ConstrainedLayoutReference
Creates one ConstrainedLayoutReference corresponding to the ConstraintLayout element with id.
createRefsFor
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.
customColor
fun KeyAttributeScope.customColor(name: String, value: Color): Unit
Sets the custom Color value at the frame of the current KeyAttributeScope.
customDistance
fun KeyAttributeScope.customDistance(name: String, value: Dp): Unit
Sets the custom Dp value at the frame of the current KeyAttributeScope.
customFloat
fun KeyAttributeScope.customFloat(name: String, value: Float): Unit
Sets the custom Float value at the frame of the current KeyAttributeScope.
customFontSize
fun KeyAttributeScope.customFontSize(name: String, value: TextUnit): Unit
Sets the custom TextUnit value at the frame of the current KeyAttributeScope.
customInt
fun KeyAttributeScope.customInt(name: String, value: Int): Unit
Sets the custom Int value at the frame of the current KeyAttributeScope.
defaultTransition
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
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.
Public properties
staggeredWeight
var ConstrainScope.staggeredWeight: Float
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 |