11package no.nordicsemi.android.common.test.simple
22
3- import androidx.compose.foundation.layout.*
3+ import androidx.compose.foundation.layout.Arrangement
4+ import androidx.compose.foundation.layout.Column
5+ import androidx.compose.foundation.layout.fillMaxSize
6+ import androidx.compose.foundation.layout.fillMaxWidth
7+ import androidx.compose.material3.AlertDialog
48import androidx.compose.material3.Button
5- import androidx.compose.material3.ExperimentalMaterial3Api
69import androidx.compose.material3.Text
710import androidx.compose.runtime.Composable
811import androidx.compose.ui.Alignment
@@ -13,10 +16,10 @@ import androidx.compose.ui.unit.dp
1316import androidx.hilt.navigation.compose.hiltViewModel
1417import no.nordicsemi.android.common.navigation.createDestination
1518import no.nordicsemi.android.common.navigation.defineDestination
19+ import no.nordicsemi.android.common.navigation.defineDialogDestination
1620import no.nordicsemi.android.common.navigation.viewmodel.SimpleNavigationViewModel
1721import no.nordicsemi.android.common.test.R
1822import no.nordicsemi.android.common.theme.NordicTheme
19- import no.nordicsemi.android.common.theme.view.NordicAppBar
2023
2124/* *
2225 * This is an example of a simple destination.
@@ -25,19 +28,43 @@ import no.nordicsemi.android.common.theme.view.NordicAppBar
2528 */
2629val Hello = createDestination<Int , Unit >(" hello" )
2730
28- val HelloDestination = defineDestination(Hello ) {
31+ private val HelloDestination = defineDestination(Hello ) {
2932 val vm: SimpleNavigationViewModel = hiltViewModel()
3033 val param = vm.parameterOf(Hello )
3134
3235 HelloScreen (
3336 param = param,
37+ onShowDialog = { vm.navigateTo(HelloDialog , " Hello World!" ) },
3438 modifier = Modifier .fillMaxWidth(),
3539 )
3640}
3741
42+ val HelloDialog = createDestination<String , Unit >(" hello-dialog" )
43+
44+ private val HelloDialogDestination = defineDialogDestination(HelloDialog ) {
45+ val vm: SimpleNavigationViewModel = hiltViewModel()
46+ val param = vm.parameterOf(HelloDialog )
47+
48+ // This should not be AlertDialog, but AlertDialogContent. This is already wrapped in Dialog.
49+ // Unfortunately, the AlertDialogContent is internal.
50+ AlertDialog (
51+ onDismissRequest = { vm.navigateUp() },
52+ title = { Text (text = param) },
53+ text = { Text (text = " This is a dialog." ) },
54+ confirmButton = {
55+ Button (onClick = { vm.navigateUp() }) {
56+ Text (text = " OK" )
57+ }
58+ },
59+ )
60+ }
61+
62+ val HelloDestinations = HelloDestination + HelloDialogDestination
63+
3864@Composable
3965private fun HelloScreen (
4066 param : Int ,
67+ onShowDialog : () -> Unit ,
4168 modifier : Modifier = Modifier ,
4269) {
4370 Column (
@@ -52,7 +79,7 @@ private fun HelloScreen(
5279
5380 Text (text = stringResource(id = R .string.hello_param, param))
5481
55- Button (onClick = { } ) {
82+ Button (onClick = onShowDialog ) {
5683 Text (text = stringResource(id = R .string.action_dialog))
5784 }
5885 }
@@ -65,6 +92,7 @@ private fun SimpleContentPreview() {
6592 NordicTheme {
6693 HelloScreen (
6794 param = 0 ,
95+ onShowDialog = {},
6896 )
6997 }
7098}
0 commit comments