Created
September 29, 2020 17:45
-
-
Save jul1u5/88b616b0fff627f6e58cd9fcf0855f52 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
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