Skip to content

Instantly share code, notes, and snippets.

@Skyyo
Last active August 26, 2022 13:51
Show Gist options
  • Save Skyyo/eb72054d713688d8cca918cd6fd1e551 to your computer and use it in GitHub Desktop.
Save Skyyo/eb72054d713688d8cca918cd6fd1e551 to your computer and use it in GitHub Desktop.
@Composable
fun DraggableCardComplex(
card: CardModel,
isRevealed: Boolean,
cardOffset: Float,
onExpand: () -> Unit,
onCollapse: () -> Unit,
) {
val offsetX by remember { mutableStateOf(0f) }
val transitionState = remember {
MutableTransitionState(isRevealed).apply {
targetState = !isRevealed
}
}
val transition = updateTransition(transitionState)
val offsetTransition by transition.animateFloat(
label = "cardOffsetTransition",
transitionSpec = { tween(durationMillis = ANIMATION_DURATION) },
targetValueByState = { if (isRevealed) cardOffset - offsetX else -offsetX },
)
Card(
modifier = Modifier
.offset { IntOffset((offsetX + offsetTransition).roundToInt(), 0) }
.pointerInput(Unit) {
detectHorizontalDragGestures { change, dragAmount ->
..
}
},
content = { CardTitle(cardTitle = card.title) }
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment