From c1998490564f026914ca6d56980fb921b6d3d22a Mon Sep 17 00:00:00 2001 From: Chris Keenan <10093880+chRyNaN@users.noreply.github.com> Date: Tue, 4 Mar 2025 17:46:57 -0500 Subject: [PATCH] Hide country list sheet after connecting --- .../vpn/app/shared/feature/country/CountryListScreen.kt | 9 ++++++--- .../app/shared/feature/country/CountryListStateModel.kt | 3 ++- .../app/shared/feature/country/CountryListViewModel.kt | 6 ++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app-shared/src/commonMain/kotlin/com/mooncloak/vpn/app/shared/feature/country/CountryListScreen.kt b/app-shared/src/commonMain/kotlin/com/mooncloak/vpn/app/shared/feature/country/CountryListScreen.kt index 3b6bbcc..3743292 100644 --- a/app-shared/src/commonMain/kotlin/com/mooncloak/vpn/app/shared/feature/country/CountryListScreen.kt +++ b/app-shared/src/commonMain/kotlin/com/mooncloak/vpn/app/shared/feature/country/CountryListScreen.kt @@ -3,7 +3,6 @@ package com.mooncloak.vpn.app.shared.feature.country import androidx.compose.animation.AnimatedContent import androidx.compose.animation.EnterTransition import androidx.compose.animation.ExitTransition -import androidx.compose.animation.core.snap import androidx.compose.animation.core.tween import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut @@ -26,7 +25,6 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip @@ -60,7 +58,6 @@ public fun CountryListScreen( } val viewModel = remember { componentDependencies.viewModel } val snackbarHostState = remember { SnackbarHostState() } - val coroutineScope = rememberCoroutineScope() val countryLazyListState = rememberLazyListState() val regionLazyListState = rememberLazyListState() @@ -70,6 +67,12 @@ public fun CountryListScreen( viewModel.load() } + LaunchedEffect(viewModel.state.current.value.hideSheet) { + if (viewModel.state.current.value.hideSheet) { + sheetState.hide() + } + } + ManagedModalBottomSheet( modifier = modifier, sheetState = sheetState diff --git a/app-shared/src/commonMain/kotlin/com/mooncloak/vpn/app/shared/feature/country/CountryListStateModel.kt b/app-shared/src/commonMain/kotlin/com/mooncloak/vpn/app/shared/feature/country/CountryListStateModel.kt index d1d4a05..752041c 100644 --- a/app-shared/src/commonMain/kotlin/com/mooncloak/vpn/app/shared/feature/country/CountryListStateModel.kt +++ b/app-shared/src/commonMain/kotlin/com/mooncloak/vpn/app/shared/feature/country/CountryListStateModel.kt @@ -29,7 +29,8 @@ public data class CountryListStateModel public constructor( public val connection: VPNConnection = VPNConnection.Disconnected(), public val subscription: ServiceSubscription? = null, public val layout: LayoutStateModel = CountryListLayoutStateModel(), - public val errorMessage: String? = null + public val errorMessage: String? = null, + public val hideSheet: Boolean = false ) public val CountryListStateModel.canAppendMore: Boolean diff --git a/app-shared/src/commonMain/kotlin/com/mooncloak/vpn/app/shared/feature/country/CountryListViewModel.kt b/app-shared/src/commonMain/kotlin/com/mooncloak/vpn/app/shared/feature/country/CountryListViewModel.kt index 71c627f..76ca2da 100644 --- a/app-shared/src/commonMain/kotlin/com/mooncloak/vpn/app/shared/feature/country/CountryListViewModel.kt +++ b/app-shared/src/commonMain/kotlin/com/mooncloak/vpn/app/shared/feature/country/CountryListViewModel.kt @@ -117,6 +117,8 @@ public class CountryListViewModel @Inject public constructor( coroutineScope.launch { mutex.withLock { connectToServerInLocationCode(locationCode = country.code) + + emit { current -> current.copy(hideSheet = true) } } } } @@ -125,6 +127,8 @@ public class CountryListViewModel @Inject public constructor( coroutineScope.launch { mutex.withLock { connectToServerInLocationCode(locationCode = region.code) + + emit { current -> current.copy(hideSheet = true) } } } } @@ -133,6 +137,8 @@ public class CountryListViewModel @Inject public constructor( coroutineScope.launch { mutex.withLock { connectToServer(server = server) + + emit { current -> current.copy(hideSheet = true) } } } }