From 62001b1e85a244723c0820ea74db0292ebb57afc Mon Sep 17 00:00:00 2001 From: "Gleb O. Ivaniczkij" Date: Sat, 24 Aug 2024 14:04:34 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B0=D0=BD=D0=B8=D0=BC=D0=B0=D1=86=D0=B8=D1=8F?= =?UTF-8?q?=20=D1=81=D0=B6=D0=B0=D1=82=D0=B8=D1=8F=20Floating=20Action=20B?= =?UTF-8?q?utton=20=D0=BF=D1=80=D0=B8=20=D0=BF=D1=80=D0=BE=D0=BA=D1=80?= =?UTF-8?q?=D1=83=D1=82=D0=BA=D0=B5=20=D0=B2=D0=BD=D0=B8=D0=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cit_is_bot/ui/dialogs/ScenarioDialog.kt | 26 +++++++++++++++---- .../cit_is_bot/ui/screens/ScenariosScreen.kt | 25 +++++++++++------- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/ru/csasq/cit_is_bot/ui/dialogs/ScenarioDialog.kt b/composeApp/src/commonMain/kotlin/ru/csasq/cit_is_bot/ui/dialogs/ScenarioDialog.kt index 750ae79..e31f007 100644 --- a/composeApp/src/commonMain/kotlin/ru/csasq/cit_is_bot/ui/dialogs/ScenarioDialog.kt +++ b/composeApp/src/commonMain/kotlin/ru/csasq/cit_is_bot/ui/dialogs/ScenarioDialog.kt @@ -27,9 +27,12 @@ import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.material3.TopAppBar import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.snapshotFlow +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.input.pointer.PointerIcon import androidx.compose.ui.input.pointer.pointerHoverIcon @@ -80,6 +83,19 @@ fun ScenarioDialog( }, properties = properties, ) { + val verticalScrollState = rememberScrollState() + val floatingActionButtonExpandedState = remember { + mutableStateOf(true) + } + LaunchedEffect(verticalScrollState) { + var previousValue = 0 + snapshotFlow { + verticalScrollState.value + }.collect { + floatingActionButtonExpandedState.value = it <= previousValue + previousValue = it + } + } Scaffold( modifier = Modifier .fillMaxSize(), @@ -185,7 +201,7 @@ fun ScenarioDialog( contentDescription = null, ) }, - expanded = true, + expanded = floatingActionButtonExpandedState.value, ) }, ) { paddingValues -> @@ -193,7 +209,7 @@ fun ScenarioDialog( modifier = Modifier .fillMaxSize() .verticalScroll( - state = rememberScrollState(), + state = verticalScrollState, ) .padding(paddingValues) .padding( @@ -467,7 +483,6 @@ fun ScenarioDialog( }, isError = false, singleLine = true, - maxLines = 3, ) Spacer( modifier = Modifier @@ -484,7 +499,9 @@ fun ScenarioDialog( val optionState = remember { mutableStateOf("") } - Row { + Row( + verticalAlignment = Alignment.CenterVertically, + ) { OutlinedTextField( value = optionState.value, onValueChange = { value -> @@ -498,7 +515,6 @@ fun ScenarioDialog( label = {}, isError = false, singleLine = true, - maxLines = 3, ) Spacer( modifier = Modifier diff --git a/composeApp/src/commonMain/kotlin/ru/csasq/cit_is_bot/ui/screens/ScenariosScreen.kt b/composeApp/src/commonMain/kotlin/ru/csasq/cit_is_bot/ui/screens/ScenariosScreen.kt index f30f396..2b651cf 100644 --- a/composeApp/src/commonMain/kotlin/ru/csasq/cit_is_bot/ui/screens/ScenariosScreen.kt +++ b/composeApp/src/commonMain/kotlin/ru/csasq/cit_is_bot/ui/screens/ScenariosScreen.kt @@ -1,6 +1,5 @@ package ru.csasq.cit_is_bot.ui.screens -import androidx.compose.foundation.ScrollState import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxSize @@ -11,14 +10,12 @@ import androidx.compose.material3.ExtendedFloatingActionButton import androidx.compose.material3.Icon import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.snapshotFlow 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.navigation.NavController import cit_is_bot.composeapp.generated.resources.Res @@ -47,6 +44,19 @@ fun ScenariosScreen( paddingValues: PaddingValues, floatingActionButtonState: MutableState<(@Composable () -> Unit)?>, ) { + val verticalScrollState = rememberScrollState() + val floatingActionButtonExpandedState = remember { + mutableStateOf(true) + } + LaunchedEffect(verticalScrollState) { + var previousValue = 0 + snapshotFlow { + verticalScrollState.value + }.collect { + floatingActionButtonExpandedState.value = it <= previousValue + previousValue = it + } + } Column( modifier = Modifier .padding( @@ -54,15 +64,12 @@ fun ScenariosScreen( ) .fillMaxSize() .verticalScroll( - state = rememberScrollState(), + state = verticalScrollState, ), ) { val scenarioDialogState = remember { mutableStateOf(null) } - val floatingActionButtonExpandedState = remember { - mutableStateOf(true) - } floatingActionButtonState.value = @Composable { ExtendedFloatingActionButton( text = {