Skip to content

Instantly share code, notes, and snippets.

@sergenes
Last active June 26, 2021 15:27
Show Gist options
  • Save sergenes/8f9634598320820887bf4d076120953c to your computer and use it in GitHub Desktop.
Save sergenes/8f9634598320820887bf4d076120953c to your computer and use it in GitHub Desktop.
@Composable
fun StudyCardDeck(
current: Int,
visible: Int,
dataSource: List<StudyCard>
) {
val topCardIdx = 0
val count = dataSource.size
val visibleCards: Int = StrictMath.min(visible, dataSource.size - current)
Box(Modifier.fillMaxSize()) {
repeat(visibleCards) { idx ->
// index in data source
val index = current + idx
val card = dataSource[index]
val colorIndex = card.index % colors.size
val cardColor = colors[colorIndex]
val data = card.frontVal
val zIndex = 100f - idx
val scaleX = calculateScale(idx)
val offsetY = calculateOffset(idx)
val cardModifier = Modifier
.scale(scaleX, 1f)
.offset { IntOffset(0, offsetY) }
.align(Alignment.TopCenter)
.zIndex(zIndex)
.size(cardWidth, cardHeight)
StudyCardView(
backgroundColor = cardColor,
side = CardFlipState.FRONT_FACE,
modifier = cardModifier,
content = { frontSideColor ->
StudyCardsContent(
data, frontSideColor
)
},
bottomBar = { frontSideColor ->
if (idx == topCardIdx) {
StudyCardsBottomBar(
card.index, count, CardFlipState.FRONT_FACE, frontSideColor,
leftActionHandler = { buttonOnSide ->
},
rightActionHandler = { }
)
}
}
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment