Last active
September 15, 2023 17:50
-
-
Save AungThiha/2fd57b218da28a5612c436e6de95820a to your computer and use it in GitHub Desktop.
Used in article "Jetpack Compose Anchored Draggable Item in MotionLayout"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| val draggedDownAnchorTop = with(LocalDensity.current) { 200.dp.toPx() } | |
| val anchors = DraggableAnchors { | |
| AnchoredDraggableCardState.DRAGGED_DOWN at draggedDownAnchorTop | |
| AnchoredDraggableCardState.DRAGGED_UP at 0f | |
| } | |
| val density = LocalDensity.current | |
| val anchoredDraggableState = remember { | |
| AnchoredDraggableState( | |
| initialValue = AnchoredDraggableCardState.DRAGGED_DOWN, | |
| anchors = anchors, | |
| positionalThreshold = { distance: Float -> distance * 0.5f }, | |
| velocityThreshold = { with(density) { 100.dp.toPx() } }, | |
| animationSpec = tween(), | |
| ) | |
| } | |
| val offset = if (anchoredDraggableState.offset.isNaN()) 0f else anchoredDraggableState.offset | |
| val progress = (1 - (offset / draggedDownAnchorTop)).coerceIn(0f, 1f) | |
| ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment