Last active
July 3, 2021 16:21
-
-
Save sergenes/b32eae8a8594853b58bc66c07cad16b5 to your computer and use it in GitHub Desktop.
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
data class StudyCardDeckEvents( | |
val cardWidth: Float, | |
val cardHeight: Float, | |
val model: StudyCardDeckModel, | |
val peepHandler: () -> Unit, | |
val playHandler: (String, String) -> Unit, | |
val nextHandler: () -> Unit, | |
val actionCallback: (String) -> Unit = {} | |
) { | |
val cardSwipe: CardSwipeAnimation = CardSwipeAnimation( | |
model = model, | |
cardWidth = cardWidth, | |
cardHeight = cardHeight | |
) | |
val flipCard = FlipCardAnimation(peepHandler) | |
val cardsInDeck = CardsInDeckAnimation(paddingOffset, model.count) | |
@SuppressLint("ModifierFactoryExtensionFunction") | |
fun makeCardModifier( | |
coroutineScope: CoroutineScope, | |
topCardIndex: Int, | |
idx: Int | |
): Modifier { | |
return if (idx > topCardIndex) { | |
Modifier | |
.scale(cardsInDeck.scaleX(idx), 1f) | |
.offset { cardsInDeck.offset(idx) } | |
} else { | |
Modifier | |
.scale(flipCard.scaleX(), flipCard.scaleY()) | |
.offset { cardSwipe.toIntOffset() } | |
.pointerInput(Unit) { | |
detectDragGestures( | |
onDragEnd = { | |
cardSwipe.animateToTarget( | |
coroutineScope, | |
CardSwipeState.DRAGGING | |
) { | |
if (it) { | |
nextHandler() | |
coroutineScope.launch { | |
flipCard.backToInitState() | |
} | |
} | |
cardsInDeck.backToInitState() | |
} | |
}, | |
onDrag = { change, _ -> | |
cardSwipe.draggingCard(coroutineScope, change) { | |
cardsInDeck.pushBackToTheFront() | |
} | |
} | |
) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment