@@ -47,6 +47,7 @@ import androidx.compose.ui.unit.dp
4747import androidx.compose.ui.unit.sp
4848import androidx.constraintlayout.compose.*
4949import java.util.*
50+ import kotlin.math.absoluteValue
5051
5152
5253@Preview(group = " constraintlayout1" )
@@ -1672,19 +1673,11 @@ public fun MotionExample11() {
16721673
16731674}
16741675
1675-
1676- @OptIn(ExperimentalMaterialApi ::class )
16771676@Preview(group = " motion12" )
16781677@Composable
1679- public fun MotionExample12 () {
1680- var componentHeight by remember { mutableStateOf(1000f ) }
1681- var corners by remember { mutableStateOf(400F ) }
1682-
1683- val swipeableState = rememberSwipeableState(" Bottom" )
1684- val anchors = mapOf (0f to " Bottom" , componentHeight to " Top" )
1685-
1686- val mprogress = (swipeableState.offset.value / componentHeight)
1687-
1678+ fun MotionExample12 () {
1679+ val motionState = rememberMotionLayoutState()
1680+ val corners = 400 - ((motionState.currentProgress * 100 ) * 4 ).coerceAtMost(400f )
16881681
16891682 MotionLayout (motionScene = MotionScene (
16901683 """ {
@@ -1761,6 +1754,13 @@ public fun MotionExample12() {
17611754 from: 'start',
17621755 to: 'end',
17631756 pathMotionArc: 'startHorizontal',
1757+ onSwipe: {
1758+ anchor: 'content',
1759+ direction: 'up',
1760+ side: 'top',
1761+ mode: 'velocity',
1762+ touchUp: 'decelerateComplete'
1763+ },
17641764 KeyFrames: {
17651765 KeyPositions: [
17661766 {
@@ -1784,24 +1784,10 @@ public fun MotionExample12() {
17841784 }
17851785 }"""
17861786 ),
1787- progress = mprogress,
1788- debug = EnumSet .of(MotionLayoutDebugFlags .NONE ),
1787+ motionLayoutState = motionState,
17891788 modifier = Modifier
17901789 .fillMaxSize()
17911790 .background(Color .Black )
1792- .swipeable(
1793- state = swipeableState,
1794- anchors = anchors,
1795- // resistance = null,
1796- reverseDirection = true ,
1797- thresholds = { _, _ -> FractionalThreshold (0.3f ) },
1798- orientation = Orientation .Vertical
1799- )
1800- .onSizeChanged { size ->
1801- componentHeight = size.height.toFloat()
1802- corners = 400 - ((mprogress* 100 ) * 4 )
1803- Log .d(" corners" , corners.toString())
1804- }
18051791 ) {
18061792 Box (
18071793 modifier = Modifier
@@ -1814,20 +1800,16 @@ public fun MotionExample12() {
18141800 .layoutId(" box1" )
18151801 .background(Color .Green )
18161802 )
1817-
18181803 Text (
18191804 text = " MotionLayout example" ,
18201805 fontSize = 18 .sp,
18211806 modifier = Modifier .layoutId(" title" )
18221807 )
1823-
18241808 Box (
18251809 modifier = Modifier
18261810 .layoutId(" circle" )
18271811 .clip(CircleShape )
18281812 .background(Color .Red )
18291813 )
1830-
18311814 }
1832-
18331815}
0 commit comments