@@ -47,6 +47,7 @@ import androidx.compose.ui.unit.dp
47
47
import androidx.compose.ui.unit.sp
48
48
import androidx.constraintlayout.compose.*
49
49
import java.util.*
50
+ import kotlin.math.absoluteValue
50
51
51
52
52
53
@Preview(group = " constraintlayout1" )
@@ -1672,19 +1673,11 @@ public fun MotionExample11() {
1672
1673
1673
1674
}
1674
1675
1675
-
1676
- @OptIn(ExperimentalMaterialApi ::class )
1677
1676
@Preview(group = " motion12" )
1678
1677
@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 )
1688
1681
1689
1682
MotionLayout (motionScene = MotionScene (
1690
1683
""" {
@@ -1761,6 +1754,13 @@ public fun MotionExample12() {
1761
1754
from: 'start',
1762
1755
to: 'end',
1763
1756
pathMotionArc: 'startHorizontal',
1757
+ onSwipe: {
1758
+ anchor: 'content',
1759
+ direction: 'up',
1760
+ side: 'top',
1761
+ mode: 'velocity',
1762
+ touchUp: 'decelerateComplete'
1763
+ },
1764
1764
KeyFrames: {
1765
1765
KeyPositions: [
1766
1766
{
@@ -1784,24 +1784,10 @@ public fun MotionExample12() {
1784
1784
}
1785
1785
}"""
1786
1786
),
1787
- progress = mprogress,
1788
- debug = EnumSet .of(MotionLayoutDebugFlags .NONE ),
1787
+ motionLayoutState = motionState,
1789
1788
modifier = Modifier
1790
1789
.fillMaxSize()
1791
1790
.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
- }
1805
1791
) {
1806
1792
Box (
1807
1793
modifier = Modifier
@@ -1814,20 +1800,16 @@ public fun MotionExample12() {
1814
1800
.layoutId(" box1" )
1815
1801
.background(Color .Green )
1816
1802
)
1817
-
1818
1803
Text (
1819
1804
text = " MotionLayout example" ,
1820
1805
fontSize = 18 .sp,
1821
1806
modifier = Modifier .layoutId(" title" )
1822
1807
)
1823
-
1824
1808
Box (
1825
1809
modifier = Modifier
1826
1810
.layoutId(" circle" )
1827
1811
.clip(CircleShape )
1828
1812
.background(Color .Red )
1829
1813
)
1830
-
1831
1814
}
1832
-
1833
1815
}
0 commit comments