commonMain.com.softartdev.theme.material.ThemeDialog.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of theme-material Show documentation
Show all versions of theme-material Show documentation
Kotlin Multiplatform library for easy switching Dark/Light Material themes on Compose.
package com.softartdev.theme.material
import androidx.compose.material.AlertDialog
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import com.softartdev.theme.pref.ThemeEnum
import io.github.softartdev.theme_prefs.generated.resources.Res
import io.github.softartdev.theme_prefs.generated.resources.cancel
import io.github.softartdev.theme_prefs.generated.resources.choose_theme
import io.github.softartdev.theme_prefs.generated.resources.ok
import org.jetbrains.compose.resources.stringResource
@Composable
fun ThemeDialog(
darkThemeState: MutableState = mutableStateOf(ThemeEnum.SystemDefault),
writePref: (ThemeEnum) -> Unit = {},
dismissDialog: () -> Unit = {}
) {
val previousState = remember { darkThemeState.value }
AlertDialog(
onDismissRequest = dismissDialog,
title = { Text(stringResource(Res.string.choose_theme)) },
text = { RadioDialogContent(darkThemeState) },
confirmButton = {
Button(onClick = {
writePref(darkThemeState.value)
dismissDialog()
}) { Text(stringResource(Res.string.ok)) }
},
dismissButton = {
Button(onClick = {
darkThemeState.value = previousState
dismissDialog()
}) { Text(stringResource(Res.string.cancel)) }
},
)
}