Last active
January 5, 2021 22:29
-
-
Save mitchtabian/0b9ae43d20f1319d69e57723213ea6c2 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
setContent{ | |
val showSnackbar = remember{ mutableStateOf(false)} | |
Column{ | |
Button( | |
onClick = { | |
showSnackbar.value = true | |
} | |
) { | |
Text("Show snackbar") | |
} | |
SimpleSnackbarDemo( | |
show = showSnackbar.value, | |
onHideSnackbar = { | |
showSnackbar.value = false | |
} | |
) | |
} | |
} | |
@Composable | |
fun SnackbarDemo( | |
show: Boolean, | |
onHideSnackbar: () -> Unit, | |
){ | |
ConstraintLayout( | |
modifier = Modifier.fillMaxSize() | |
) { | |
val snackbar = createRef() | |
if(show){ | |
Snackbar( | |
modifier = Modifier.constrainAs(snackbar) { | |
bottom.linkTo(parent.bottom) | |
start.linkTo(parent.start) | |
end.linkTo(parent.end) | |
}, | |
action = { | |
Text( | |
"Hide", | |
modifier = Modifier.clickable(onClick = onHideSnackbar), | |
style = MaterialTheme.typography.h5 | |
) | |
}, | |
) { | |
Text(text = "Hey look a snackbar") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment