Skip to content

Instantly share code, notes, and snippets.

@AungThiha
Last active September 15, 2023 17:50
Show Gist options
  • Select an option

  • Save AungThiha/2fd57b218da28a5612c436e6de95820a to your computer and use it in GitHub Desktop.

Select an option

Save AungThiha/2fd57b218da28a5612c436e6de95820a to your computer and use it in GitHub Desktop.
Used in article "Jetpack Compose Anchored Draggable Item in MotionLayout"
...
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