Last active
August 26, 2022 13:51
-
-
Save Skyyo/eb72054d713688d8cca918cd6fd1e551 to your computer and use it in GitHub Desktop.
This file contains 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
@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