Внесены изменения в архитектуру всплывающей кнопки и диалогового окна

Этот коммит содержится в:
Глеб Иваницкий 2024-08-21 23:03:31 +03:00
родитель 222e8d1e1f
Коммит a8b7685c9f
3 изменённых файлов: 42 добавлений и 26 удалений

Просмотреть файл

@ -48,7 +48,7 @@ sealed class Screen(
title = "Дашборд", title = "Дашборд",
icon = Res.drawable.baseline_dashboard_24, icon = Res.drawable.baseline_dashboard_24,
) )
data object Messages : Screen( data object Scenarios : Screen(
route = "scenarios", route = "scenarios",
title = "Сценарии", title = "Сценарии",
icon = Res.drawable.baseline_edit_calendar_24, icon = Res.drawable.baseline_edit_calendar_24,
@ -75,12 +75,18 @@ fun App() {
val snackbarHostState = remember { val snackbarHostState = remember {
SnackbarHostState() SnackbarHostState()
} }
val scheduleFloatingActionButtonVisibleState = remember { val floatingActionButtonVisibleState = remember {
mutableStateOf(false) mutableStateOf(false)
} }
val floatingActionButtonOnClickState = remember {
mutableStateOf<(() -> Unit)?>(null)
}
val createRuleDialogOpeningState = remember { val createRuleDialogOpeningState = remember {
mutableStateOf(false) mutableStateOf(false)
} }
val floatingActionButtonExpandedState = remember {
mutableStateOf(true)
}
Scaffold( Scaffold(
topBar = { topBar = {
TopAppBar( TopAppBar(
@ -96,7 +102,7 @@ fun App() {
val navBackStackEntry = navController.currentBackStackEntryAsState() val navBackStackEntry = navController.currentBackStackEntryAsState()
val items = listOf( val items = listOf(
Screen.Dashboard, Screen.Dashboard,
Screen.Messages, Screen.Scenarios,
Screen.Chats, Screen.Chats,
Screen.Users, Screen.Users,
) )
@ -138,7 +144,7 @@ fun App() {
}, },
floatingActionButton = { floatingActionButton = {
AnimatedVisibility( AnimatedVisibility(
visible = scheduleFloatingActionButtonVisibleState.value, visible = floatingActionButtonVisibleState.value,
enter = fadeIn() + expandHorizontally(), enter = fadeIn() + expandHorizontally(),
exit = fadeOut() + shrinkHorizontally() exit = fadeOut() + shrinkHorizontally()
) { ) {
@ -154,10 +160,8 @@ fun App() {
contentDescription = null, contentDescription = null,
) )
}, },
onClick = { onClick = floatingActionButtonOnClickState.value ?: {},
createRuleDialogOpeningState.value = true expanded = floatingActionButtonExpandedState.value,
},
expanded = true,
) )
} }
}, },
@ -167,27 +171,24 @@ fun App() {
startDestination = Screen.Dashboard.route, startDestination = Screen.Dashboard.route,
) { ) {
composable(Screen.Dashboard.route) { composable(Screen.Dashboard.route) {
scheduleFloatingActionButtonVisibleState.value = false floatingActionButtonVisibleState.value = false
DashboardScreen(navController, paddingValues) DashboardScreen(navController, paddingValues)
} }
composable(Screen.Messages.route) { composable(Screen.Scenarios.route) {
ScenariosScreen(navController, paddingValues) floatingActionButtonVisibleState.value = true
scheduleFloatingActionButtonVisibleState.value = true ScenariosScreen(
navController,
// when { paddingValues,
// createRuleDialogOpeningState.value -> CallProtectionRuleDialog( floatingActionButtonOnClickState,
// database = database, floatingActionButtonExpandedState,
// scheduleRule = null, )
// state = createRuleDialogOpeningState,
// )
// }
} }
composable(Screen.Chats.route) { composable(Screen.Chats.route) {
scheduleFloatingActionButtonVisibleState.value = false floatingActionButtonVisibleState.value = false
ChatsScreen(navController, paddingValues) ChatsScreen(navController, paddingValues)
} }
composable(Screen.Users.route) { composable(Screen.Users.route) {
scheduleFloatingActionButtonVisibleState.value = false floatingActionButtonVisibleState.value = false
UsersScreen(navController, paddingValues) UsersScreen(navController, paddingValues)
} }
} }

Просмотреть файл

@ -51,7 +51,7 @@ fun ScenarioDialog(
TopAppBar( TopAppBar(
title = { title = {
Text( Text(
text = scenarioDialogState.value?.let { text = scenarioDialogState.value?.id?.let {
"Изменить сценарий" "Изменить сценарий"
} ?: "Добавить сценарий", } ?: "Добавить сценарий",
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,

Просмотреть файл

@ -1,24 +1,28 @@
package ru.csasq.cit_is_bot.ui.screens package ru.csasq.cit_is_bot.ui.screens
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController import androidx.navigation.NavController
import ru.csasq.cit_is_bot.ui.components.SwitchButton import ru.csasq.cit_is_bot.ui.components.SwitchButton
import ru.csasq.cit_is_bot.ui.dialogs.ScenarioDialog import ru.csasq.cit_is_bot.ui.dialogs.ScenarioDialog
data class Scenario( data class Scenario(
val id: Int, val id: Int? = null,
val name: String, val name: String,
val daysOfWeek: String, val daysOfWeek: String,
val time: String, val time: String,
@ -35,6 +39,8 @@ val scenarioList = listOf(
fun ScenariosScreen( fun ScenariosScreen(
navController: NavController, navController: NavController,
paddingValues: PaddingValues, paddingValues: PaddingValues,
floatingActionButtonOnClickState: MutableState<(() -> Unit)?>,
floatingActionButtonExpandedState: MutableState<Boolean>,
) { ) {
Column( Column(
modifier = Modifier modifier = Modifier
@ -49,6 +55,15 @@ fun ScenariosScreen(
val scenarioDialogState = remember { val scenarioDialogState = remember {
mutableStateOf<Scenario?>(null) mutableStateOf<Scenario?>(null)
} }
floatingActionButtonOnClickState.value = {
scenarioDialogState.value = Scenario(
name = "",
daysOfWeek = "",
time = "",
messageNumber = "",
isEnabled = true,
)
}
scenarioList.forEach { scenarioList.forEach {
val scenarioSwitchState = remember { val scenarioSwitchState = remember {
mutableStateOf(it.isEnabled) mutableStateOf(it.isEnabled)