Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import io.github.openflocon.flocondesktop.features.table.tableRoutes
import io.github.openflocon.library.designsystem.FloconTheme
import io.github.openflocon.navigation.FloconNavigation
import io.github.openflocon.navigation.MainFloconNavigationState
import io.github.openflocon.navigation.scene.BigDialogSceneStrategy
import io.github.openflocon.navigation.scene.DialogSceneStrategy
import io.github.openflocon.navigation.scene.PanelSceneStrategy
import io.github.openflocon.navigation.scene.WindowSceneStrategy
Expand Down Expand Up @@ -58,6 +59,7 @@ private fun Content(
sceneStrategy = PanelSceneStrategy()
.then(WindowSceneStrategy())
.then(DialogSceneStrategy())
.then(BigDialogSceneStrategy())
.then(
MenuSceneStrategy(
menuContent = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
@file:OptIn(ExperimentalMaterial3Api::class)

package io.github.openflocon.navigation.scene

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.dropShadow
import androidx.compose.ui.graphics.shadow.Shadow
import androidx.compose.ui.unit.dp
import androidx.navigation3.runtime.NavEntry
import androidx.navigation3.scene.OverlayScene
import androidx.navigation3.scene.Scene
import androidx.navigation3.scene.SceneStrategy
import androidx.navigation3.scene.SceneStrategyScope
import io.github.openflocon.library.designsystem.FloconTheme
import io.github.openflocon.library.designsystem.components.FloconIcon
import io.github.openflocon.library.designsystem.components.FloconIconButton
import io.github.openflocon.library.designsystem.components.FloconScaffold
import io.github.openflocon.navigation.FloconRoute

@Immutable
private data class BigDialogScene(
private val entry: NavEntry<FloconRoute>,
private val properties: BigDialogProperties,
override val previousEntries: List<NavEntry<FloconRoute>>,
override val overlaidEntries: List<NavEntry<FloconRoute>>,
private val onBack: () -> Unit,
) : OverlayScene<FloconRoute> {
override val key: Any = BigDialogSceneStrategy.BIG_DIALOG
override val entries: List<NavEntry<FloconRoute>> = listOf(entry)
override val content: @Composable (() -> Unit) = {
FloconScaffold(
topBar = {
TopAppBar(
title = {
Text(properties.title)
},
actions = {
FloconIconButton(
onClick = onBack
) {
FloconIcon(
imageVector = Icons.Default.Close
)
}
},
colors = TopAppBarDefaults.topAppBarColors(
containerColor = FloconTheme.colorPalette.primary,
titleContentColor = FloconTheme.colorPalette.onPrimary,
actionIconContentColor = FloconTheme.colorPalette.onPrimary
)
)
},
containerColor = FloconTheme.colorPalette.primary.copy(alpha = 0.5f),
modifier = Modifier
.fillMaxSize()
.clickable(
onClick = onBack,
indication = null,
interactionSource = null
)
.padding(64.dp)
.dropShadow(
shape = RoundedCornerShape(12.dp),
shadow = Shadow(
radius = 4.dp,
color = FloconTheme.colorPalette.onAccent
)
)
.clip(RoundedCornerShape(12.dp))
.background(FloconTheme.colorPalette.primary)
.padding(16.dp)
) {
Comment thread
rteyssandier marked this conversation as resolved.
Box(
modifier = Modifier
.fillMaxSize()
.padding(it)
) {
entry.Content()
}
}
}
}

data class BigDialogProperties(
val title: String
)

class BigDialogSceneStrategy : SceneStrategy<FloconRoute> {

override fun SceneStrategyScope<FloconRoute>.calculateScene(
entries: List<NavEntry<FloconRoute>>
): Scene<FloconRoute>? {
val lastEntry = entries.lastOrNull()
val dialogProperties = lastEntry?.metadata?.get(BIG_DIALOG) as? BigDialogProperties
return dialogProperties?.let { properties ->
BigDialogScene(
entry = lastEntry,
properties = properties,
previousEntries = entries.dropLast(1),
overlaidEntries = entries.dropLast(1),
onBack = onBack,
)
}
}

companion object {
const val BIG_DIALOG = "BIG_DIALOG"

fun bigDialog(properties: BigDialogProperties): Map<String, Any> = mapOf(BIG_DIALOG to properties)
}

}