@@ -9,20 +9,21 @@ import androidx.compose.material3.Text
99import androidx.compose.material3.TextButton
1010import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi
1111import androidx.compose.material3.adaptive.WindowAdaptiveInfo
12- import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
12+ import androidx.compose.material3.adaptive.currentWindowAdaptiveInfoV2
1313import androidx.compose.material3.adaptive.layout.calculatePaneScaffoldDirective
1414import androidx.compose.material3.adaptive.navigation3.ListDetailSceneStrategy
1515import androidx.compose.material3.adaptive.navigation3.rememberListDetailSceneStrategy
1616import androidx.compose.runtime.Composable
1717import androidx.compose.runtime.collectAsState
1818import androidx.compose.runtime.getValue
19+ import androidx.compose.runtime.remember
1920import androidx.compose.ui.Modifier
2021import androidx.compose.ui.platform.LocalConfiguration
2122import androidx.compose.ui.res.stringResource
2223import androidx.compose.ui.unit.dp
23- import androidx.compose.ui.window.Dialog
2424import androidx.navigation3.runtime.NavKey
2525import androidx.navigation3.runtime.entryProvider
26+ import androidx.navigation3.scene.DialogSceneStrategy
2627import androidx.navigation3.ui.NavDisplay
2728import androidx.window.core.layout.WindowSizeClass.Companion.WIDTH_DP_MEDIUM_LOWER_BOUND
2829import io.simplelogin.android.R
@@ -94,8 +95,7 @@ fun AppRoot(
9495 onOpenDrawer : () -> Unit
9596) = with (viewModel) {
9697 val backStack by navBackStack.collectAsState()
97- val dialogStack by dialogStack.collectAsState()
98- val activeDialog = dialogStack.lastOrNull()
98+ val showLogOutDialog by showLogOutDialog.collectAsState()
9999 val configuration = LocalConfiguration .current
100100 val screenWidth = configuration.screenWidthDp.dp
101101
@@ -104,19 +104,22 @@ fun AppRoot(
104104 } else {
105105 screenWidth * 0.5f
106106 }
107- val windowAdaptiveInfo = currentWindowAdaptiveInfo()
107+ val windowAdaptiveInfo = currentWindowAdaptiveInfoV2()
108+ val numberOfPanes = if (windowAdaptiveInfo.supportsMultiplePanes()) 2 else 1
108109 val listDetailSceneStrategy = rememberListDetailSceneStrategy<NavKey >(
109110 directive = calculatePaneScaffoldDirective(windowAdaptiveInfo).copy(
110111 defaultPanePreferredWidth = listPaneWidth,
111- maxHorizontalPartitions = if (windowAdaptiveInfo.supportsMultiplePanes()) 2 else 1 ,
112+ maxHorizontalPartitions = numberOfPanes ,
112113 horizontalPartitionSpacerSize = 0 .dp
113114 )
114115 )
116+ val dialogStrategy = remember { DialogSceneStrategy <NavKey >() }
117+ val dialogMetadata = if (numberOfPanes > 1 ) DialogSceneStrategy .dialog() else emptyMap()
115118
116119 NavDisplay (
117120 modifier = modifier,
118121 backStack = backStack,
119- sceneStrategies = listOf (listDetailSceneStrategy),
122+ sceneStrategies = listOf (listDetailSceneStrategy, dialogStrategy ),
120123 entryProvider = entryProvider {
121124 entry<InitializationDestination > {}
122125
@@ -139,7 +142,7 @@ fun AppRoot(
139142 )
140143 }
141144
142- entry<CreateAliasDestination > { key ->
145+ entry<CreateAliasDestination >(metadata = dialogMetadata) { key ->
143146 CreateAliasScreen (
144147 apiKeyValue = key.apiKey,
145148 onAliasCreated = viewModel::handleCreatedAlias,
@@ -182,52 +185,46 @@ fun AppRoot(
182185 )
183186 }
184187
185- entry<DeviceSettingsDestination > {
188+ entry<DeviceSettingsDestination >(metadata = dialogMetadata) {
186189 DeviceSettingsScreen (onDismiss = viewModel::goBack)
187190 }
188191
189- entry<AccountSettingsDestination > { key ->
192+ entry<AccountSettingsDestination >(metadata = dialogMetadata) { key ->
190193 AccountSettingsScreen (
191194 apiKeyValue = key.apiKey,
192195 onDismiss = viewModel::goBack
193196 )
194197 }
195198
196- entry<MailboxesDestination > { key ->
199+ entry<MailboxesDestination >(metadata = dialogMetadata) { key ->
197200 MailboxesScreen (
198201 apiKeyValue = key.apiKey,
199202 onDismiss = viewModel::goBack
200203 )
201204 }
202205
203- entry<CustomDomainsDestination > { key ->
206+ entry<CustomDomainsDestination >(metadata = dialogMetadata) { key ->
204207 CustomDomainsScreen (
205208 apiKeyValue = key.apiKey,
206209 onViewDetails = {
207- viewModel.showCustomDomainDetails(
208- domain = it,
209- asDialog = false
210- )
210+ viewModel.showCustomDomainDetails(domain = it)
211211 },
212212 onDismiss = viewModel::goBack
213213 )
214214 }
215215
216- entry<CustomDomainDetailsDestination > { key ->
216+ entry<CustomDomainDetailsDestination >(metadata = dialogMetadata) { key ->
217217 CustomDomainDetailsScreen (
218218 domain = key.domain,
219219 apiKeyValue = key.apiKey,
220220 onDismiss = viewModel::goBack,
221221 onViewDeletedAliases = {
222- viewModel.showCustomDomainDeletedAliases(
223- domain = key.domain,
224- asDialog = false
225- )
222+ viewModel.showCustomDomainDeletedAliases(domain = key.domain)
226223 }
227224 )
228225 }
229226
230- entry<CustomDomainDeletedAliasesDestination > { key ->
227+ entry<CustomDomainDeletedAliasesDestination >(metadata = dialogMetadata) { key ->
231228 CustomDomainDeletedAliasesScreen (
232229 domain = key.domain,
233230 apiKeyValue = key.apiKey,
@@ -237,8 +234,8 @@ fun AppRoot(
237234 }
238235 )
239236
240- when (activeDialog ) {
241- AppRootDialog . LogOut -> AlertDialog (
237+ if (showLogOutDialog ) {
238+ AlertDialog (
242239 onDismissRequest = ::dismissActiveDialog,
243240 title = { Text (stringResource(R .string.sign_out)) },
244241 text = { Text (stringResource(R .string.sign_out_message)) },
@@ -253,58 +250,8 @@ fun AppRoot(
253250 }
254251 }
255252 )
256-
257- AppRootDialog .DeviceSettings -> Dialog (onDismissRequest = ::dismissActiveDialog) {
258- DeviceSettingsScreen (onDismiss = ::dismissActiveDialog)
259- }
260-
261- is AppRootDialog .AccountSettings -> Dialog (onDismissRequest = ::dismissActiveDialog) {
262- AccountSettingsScreen (
263- apiKeyValue = activeDialog.apiKey.value,
264- onDismiss = ::dismissActiveDialog
265- )
266- }
267-
268- is AppRootDialog .Mailboxes -> Dialog (onDismissRequest = ::dismissActiveDialog) {
269- MailboxesScreen (
270- apiKeyValue = activeDialog.apiKey.value,
271- onDismiss = ::dismissActiveDialog
272- )
273- }
274-
275- is AppRootDialog .CustomDomains -> Dialog (onDismissRequest = ::dismissActiveDialog) {
276- CustomDomainsScreen (
277- apiKeyValue = activeDialog.apiKey.value,
278- onViewDetails = { showCustomDomainDetails(domain = it, asDialog = true ) },
279- onDismiss = ::dismissActiveDialog
280- )
281- }
282-
283- is AppRootDialog .CustomDomainDetails -> Dialog (onDismissRequest = ::dismissActiveDialog) {
284- CustomDomainDetailsScreen (
285- domain = activeDialog.domain,
286- apiKeyValue = activeDialog.apiKey.value,
287- onDismiss = ::dismissActiveDialog,
288- onViewDeletedAliases = {
289- viewModel.showCustomDomainDeletedAliases(
290- domain = activeDialog.domain,
291- asDialog = true
292- )
293- }
294- )
295- }
296-
297- is AppRootDialog .CustomDomainDeletedAliases -> Dialog (onDismissRequest = ::dismissActiveDialog) {
298- CustomDomainDeletedAliasesScreen (
299- domain = activeDialog.domain,
300- apiKeyValue = activeDialog.apiKey.value,
301- onDismiss = ::dismissActiveDialog
302- )
303- }
304-
305- null -> Unit
306253 }
307254}
308255
309- fun WindowAdaptiveInfo.supportsMultiplePanes (): Boolean =
256+ private fun WindowAdaptiveInfo.supportsMultiplePanes (): Boolean =
310257 windowSizeClass.isWidthAtLeastBreakpoint(WIDTH_DP_MEDIUM_LOWER_BOUND )
0 commit comments