Skip to content

Commit

Permalink
fullscreen dialog added, bottom sheet can be animated on show, style …
Browse files Browse the repository at this point in the history
…options (icon position), small improvements
  • Loading branch information
MFlisar committed Jan 4, 2025
1 parent de01998 commit bc11b43
Show file tree
Hide file tree
Showing 18 changed files with 688 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Info
import androidx.compose.material3.Button
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
Expand All @@ -26,9 +27,9 @@ import androidx.compose.ui.window.application
import androidx.compose.ui.window.rememberWindowState
import com.michaelflisar.composedialogs.core.ComposeDialogStyle
import com.michaelflisar.composedialogs.core.DialogButtonType
import com.michaelflisar.composedialogs.core.DialogButtons
import com.michaelflisar.composedialogs.core.DialogDefaults
import com.michaelflisar.composedialogs.core.DialogEvent
import com.michaelflisar.composedialogs.core.StyleOptions
import com.michaelflisar.composedialogs.core.rememberDialogState
import com.michaelflisar.composedialogs.dialogs.color.DialogColor
import com.michaelflisar.composedialogs.dialogs.color.rememberDialogColor
Expand Down Expand Up @@ -57,7 +58,9 @@ import com.michaelflisar.composedialogs.dialogs.progress.styleWindowsProgressDia
import com.michaelflisar.composedialogs.dialogs.time.DialogTime
import com.michaelflisar.composedialogs.dialogs.time.rememberDialogTime
import com.michaelflisar.composedialogs.dialogs.time.styleWindowsTimeDialog
import com.michaelflisar.toolbox.composables.MyCheckbox
import com.michaelflisar.toolbox.composables.MyDropdown
import com.michaelflisar.toolbox.composables.MyRow
import com.michaelflisar.toolbox.composables.MyTitle
import com.michaelflisar.toolbox.ui.MyScrollableLazyColumn

Expand Down Expand Up @@ -88,17 +91,23 @@ fun main() {
height = 600.dp
)
) {
val styles = listOf("Dialog", "Bottom Sheet", "Windows Dialog")
val styles = listOf("Dialog", "Bottom Sheet", "Windows Dialog", "Fullscreen Dialog")
val selectedStyle = remember { mutableStateOf(0) }
val selectedIconPosition = remember { mutableStateOf(StyleOptions.IconMode.Begin) }
val showIcon = remember { mutableStateOf(false) }
val infos = remember { mutableStateListOf<String>() }
val dialog = rememberDialogState<Dialog>(data = null)
Column(
modifier = Modifier.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
MyTitle("Dialogs")
MyDropdown(title = "Dialog Mode", items = styles, selected = selectedStyle)
FlowRow(
MyRow {
MyDropdown(modifier = Modifier.weight(1f), title = "Dialog Mode", items = styles, selected = selectedStyle)
MyCheckbox(modifier = Modifier.wrapContentWidth(), title = "Icon", checked = showIcon)
MyDropdown<StyleOptions.IconMode>(modifier = Modifier.weight(1f), title = "Icon Position", items = StyleOptions.IconMode.entries, selected = selectedIconPosition, mapper = { item, dropdown -> item.name}, enabled = showIcon.value)
}
FlowRow(
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterVertically)
) {
Expand All @@ -125,12 +134,18 @@ fun main() {
}

val getStyle = @Composable { windowsDialogStyle: @Composable () -> ComposeDialogStyle ->
val options = StyleOptions(iconMode = selectedIconPosition.value)
when (selectedStyle.value) {
0 -> DialogDefaults.styleDialog(swipeDismissable = false)
1 -> DialogDefaults.styleBottomSheet()
else -> windowsDialogStyle()
0 -> DialogDefaults.styleDialog(swipeDismissable = false, options = options)
1 -> DialogDefaults.styleBottomSheet(options = options, animateShow = true)
2 -> windowsDialogStyle()
3 -> DialogDefaults.styleFullscreenDialog()
else -> error("Invalid style")
}
}
val getIcon: (@Composable () -> Unit)? = if (showIcon.value) {
{ Icon(Icons.Default.Info, null) }
} else null

when (dialog.data) {
Dialog.Color -> {
Expand All @@ -141,6 +156,7 @@ fun main() {
DialogColor(
style = style,
title = { Text("Color Dialog") },
icon = getIcon,
state = dialog,
color = color,
alphaSupported = true,
Expand All @@ -162,6 +178,7 @@ fun main() {
DialogDate(
style = style,
title = { Text("Select Date") },
icon = getIcon,
state = dialog,
date = date,
onEvent = {
Expand All @@ -182,6 +199,7 @@ fun main() {
DialogTime(
style = style,
title = { Text("Select Time") },
icon = getIcon,
state = dialog,
time = time,
//setup = DialogTimeDefaults.setup(is24Hours = true),
Expand All @@ -202,6 +220,7 @@ fun main() {
DialogInfo(
style = style,
title = { Text("Info Dialog") },
icon = getIcon,
state = dialog,
info = "Information",
infoLabel = "Important",
Expand All @@ -218,6 +237,7 @@ fun main() {
DialogProgress(
style = style,
title = { Text("Progress Dialog") },
icon = getIcon,
state = dialog,
content = {
Text("Loading...")
Expand All @@ -236,6 +256,7 @@ fun main() {
DialogInput(
style = style,
title = { Text("Input Dialog") },
icon = getIcon,
state = dialog,
label = "Enter some text...",
value = input,
Expand All @@ -257,6 +278,7 @@ fun main() {
DialogInputNumber(
style = style,
title = { Text("Number Dialog") },
icon = getIcon,
state = dialog,
label = "Enter a valid Integer...",
value = input,
Expand All @@ -278,6 +300,7 @@ fun main() {
DialogNumberPicker(
style = style,
title = { Text("Number Picker Dialog") },
icon = getIcon,
state = dialog,
value = value,
setup = NumberPickerSetup(
Expand All @@ -302,6 +325,7 @@ fun main() {
DialogList(
style = style,
title = { Text("List Dialog") },
icon = getIcon,
description = "Some optional description",
state = dialog,
items = items,
Expand All @@ -328,45 +352,85 @@ fun main() {
DialogDefaults.styleWindowsMenuDialog("Menu Dialog")
}
val items = listOf(
MenuItem.Item("Item 1", "Description 1", { Icon(Icons.Default.Info, null) }) {
MenuItem.Item(
"Item 1",
"Description 1",
{ Icon(Icons.Default.Info, null) }) {
infos.add("Item 1 clicked")
},
MenuItem.Item("Item 2", "Description 2", { Icon(Icons.Default.Info, null) }) {
MenuItem.Item(
"Item 2",
"Description 2",
{ Icon(Icons.Default.Info, null) }) {
infos.add("Item 2 clicked")
},
MenuItem.Divider,
MenuItem.SubMenu("Sub Menu 1", "Description", { Icon(Icons.Default.Info, null) },
MenuItem.SubMenu("Sub Menu 1",
"Description",
{ Icon(Icons.Default.Info, null) },
listOf(
MenuItem.Item("Sub Item 1", "Description 1", { Icon(Icons.Default.Info, null) }) {
MenuItem.Item(
"Sub Item 1",
"Description 1",
{ Icon(Icons.Default.Info, null) }) {
infos.add("Sub Item 1 clicked")
},
MenuItem.Item("Sub Item 2", "Description 2", { Icon(Icons.Default.Info, null) }) {
MenuItem.Item(
"Sub Item 2",
"Description 2",
{ Icon(Icons.Default.Info, null) }) {
infos.add("Sub Item 2 clicked")
},
MenuItem.Item("Sub Item 3", "Description 3", { Icon(Icons.Default.Info, null) }) {
MenuItem.Item(
"Sub Item 3",
"Description 3",
{ Icon(Icons.Default.Info, null) }) {
infos.add("Sub Item 3 clicked")
},
MenuItem.SubMenu("Sub Sub Menu 4", "Description", { Icon(Icons.Default.Info, null) },
MenuItem.SubMenu("Sub Sub Menu 4",
"Description",
{ Icon(Icons.Default.Info, null) },
listOf(
MenuItem.Item("Sub Sub Item 1", "Description", { Icon(Icons.Default.Info, null) }) {
MenuItem.Item(
"Sub Sub Item 1",
"Description",
{ Icon(Icons.Default.Info, null) }) {
infos.add("Sub Sub Item 1 clicked")
},
MenuItem.Item("Sub Sub Item 2", "Description", { Icon(Icons.Default.Info, null) }) {
MenuItem.Item(
"Sub Sub Item 2",
"Description",
{ Icon(Icons.Default.Info, null) }) {
infos.add("Sub Sub Item 2 clicked")
},
MenuItem.Item("Sub Sub Item 3", "Description", { Icon(Icons.Default.Info, null) }) {
MenuItem.Item(
"Sub Sub Item 3",
"Description",
{ Icon(Icons.Default.Info, null) }) {
infos.add("Sub Sub Item 3 clicked")
},
MenuItem.Item("Sub Sub Item 4", "Description", { Icon(Icons.Default.Info, null) }) {
MenuItem.Item(
"Sub Sub Item 4",
"Description",
{ Icon(Icons.Default.Info, null) }) {
infos.add("Sub Sub Item 4 clicked")
},
MenuItem.Item("Sub Sub Item 5", "Description", { Icon(Icons.Default.Info, null) }) {
MenuItem.Item(
"Sub Sub Item 5",
"Description",
{ Icon(Icons.Default.Info, null) }) {
infos.add("Sub Sub Item 5 clicked")
},
MenuItem.Item("Sub Sub Item 6", "Description", { Icon(Icons.Default.Info, null) }) {
MenuItem.Item(
"Sub Sub Item 6",
"Description",
{ Icon(Icons.Default.Info, null) }) {
infos.add("Sub Sub Item 6 clicked")
},
MenuItem.Item("Sub Sub Item 7", "Description", { Icon(Icons.Default.Info, null) }) {
MenuItem.Item(
"Sub Sub Item 7",
"Description",
{ Icon(Icons.Default.Info, null) }) {
infos.add("Sub Sub Item 7 clicked")
},
)
Expand All @@ -380,6 +444,7 @@ fun main() {
DialogMenu(
style = style,
title = { Text("Menu Dialog") },
icon = getIcon,
items = items,
state = dialog
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.core.view.WindowInsetsControllerCompat
import com.composables.core.LocalModalWindow

@Composable
actual fun isLandscape(): Boolean =
Expand Down Expand Up @@ -57,4 +60,19 @@ actual fun DialogContentScrollableLazyColumn(
) {
content()
}
}

@Composable
actual fun updateStatusbarColor(darkStatusBar: Boolean) {
val window = LocalModalWindow.current
LaunchedEffect(darkStatusBar) {
// change system bars to transparent
//window.statusBarColor = titleBackground.toArgb()
//window.navigationBarColor = Color.Black.copy(0.33f).toArgb()

// don't forget to update the icons too
val windowInsetsController = WindowInsetsControllerCompat(window, window.decorView)
windowInsetsController.isAppearanceLightStatusBars = !darkStatusBar
//windowInsetsController.isAppearanceLightNavigationBars = false
}
}
Loading

0 comments on commit bc11b43

Please sign in to comment.