Created
April 30, 2022 00:13
-
-
Save nglauber/6a499b7db1dff496bad1c503006e73da 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 CardsGameSample() { | |
val colors = listOf( | |
Color.Red, Color.Green, Color.Blue, Color.Yellow, Color.Cyan | |
) | |
var cardCounter by remember { | |
mutableStateOf(0) | |
} | |
Column { | |
Row { | |
IconButton(onClick = { cardCounter = max(0, cardCounter - 1) }) { | |
Icon(imageVector = Icons.Default.ArrowBack, contentDescription = null) | |
} | |
IconButton(onClick = { cardCounter = min(colors.size, cardCounter + 1) }) { | |
Icon(imageVector = Icons.Default.ArrowForward, contentDescription = null) | |
} | |
} | |
} | |
Box(Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) { | |
repeat(cardCounter) { | |
val singleCardOffset = 30 | |
val totalOffset = singleCardOffset * (cardCounter - 1) / 2 | |
Box( | |
Modifier | |
.offset(x = (-totalOffset + (it * singleCardOffset)).dp) | |
.size(60.dp, 100.dp) | |
.background(colors[it]) | |
) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment