Created
June 28, 2023 07:59
-
-
Save kalactor/6ec3b84981f871a136accd3b1ab55d4d to your computer and use it in GitHub Desktop.
This code show how to implement swipe-to-dismiss in jetpack compose android.
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
@OptIn(ExperimentalMaterial3Api::class) | |
@Composable | |
fun Greeting() { | |
val dismissState = rememberDismissState() | |
SwipeToDismiss( | |
state = dismissState, | |
background = { | |
val color by animateColorAsState( | |
when (dismissState.targetValue) { | |
DismissValue.Default -> Color.Yellow | |
DismissValue.DismissedToEnd -> Color.Green | |
DismissValue.DismissedToStart -> Color.Red | |
} | |
) | |
Box( | |
modifier = Modifier | |
.fillMaxSize() | |
.background(color = color) | |
) | |
}, | |
dismissContent = { | |
CardShower() | |
} | |
) | |
} | |
@Composable | |
fun CardShower() { | |
Card( | |
modifier = Modifier | |
.fillMaxWidth() | |
.padding(8.dp) | |
) { | |
Column( | |
verticalArrangement = Arrangement.Center, | |
modifier = Modifier.padding(8.dp) | |
) { | |
Text( | |
text = "Jetpack Compose", | |
style = MaterialTheme.typography.titleMedium | |
) | |
Text(text = "Android Development") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment