Skip to content

Instantly share code, notes, and snippets.

@jul1u5
Created September 29, 2020 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jul1u5/88b616b0fff627f6e58cd9fcf0855f52 to your computer and use it in GitHub Desktop.
Save jul1u5/88b616b0fff627f6e58cd9fcf0855f52 to your computer and use it in GitHub Desktop.
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
DialogTestTheme {
App()
}
}
}
}
@Composable
fun App() {
var dialogOpen by remember { mutableStateOf(false) }
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Button(onClick = { dialogOpen = true }) {
Text("OPEN")
}
}
if (dialogOpen) {
Dialog { dialogOpen = false }
}
}
@Composable
fun Dialog(onDismiss: () -> Unit) {
val (field, setField) = remember { mutableStateOf("") }
AlertDialog(
onDismissRequest = onDismiss,
text = {
OutlinedTextField(
value = field,
onValueChange = setField,
label = {
Text("LABEL")
},
)
},
confirmButton = {
var count by remember { mutableStateOf(0) }
Button(onClick = { count++ }) {
Text("BUTTON $count")
}
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment