diff --git a/flaker-android-retrofit/src/main/java/io/rotlabs/flakerandroidretrofit/ui/FlakerActivity.kt b/flaker-android-retrofit/src/main/java/io/rotlabs/flakerandroidretrofit/ui/FlakerActivity.kt index 386288f..2b6490b 100644 --- a/flaker-android-retrofit/src/main/java/io/rotlabs/flakerandroidretrofit/ui/FlakerActivity.kt +++ b/flaker-android-retrofit/src/main/java/io/rotlabs/flakerandroidretrofit/ui/FlakerActivity.kt @@ -4,6 +4,11 @@ import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.viewModels +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.animation.expandVertically +import androidx.compose.animation.fadeIn +import androidx.compose.animation.fadeOut +import androidx.compose.animation.shrinkVertically import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize @@ -68,14 +73,16 @@ class FlakerActivity : ComponentActivity() { NetworkRequestList(modifier = Modifier.padding(scaffoldPadding), state = state) } - if (state.toShowPrefs) { - state.currentPrefs?.let { prefs -> - FlakerPrefsDialog( - onDismissRequest = viewModel::closePrefs, - onConfirmAction = viewModel::updatePrefs, - currentValues = prefs, - ) - } + AnimatedVisibility( + visible = state.toShowPrefs, + enter = fadeIn() + expandVertically { 0 }, + exit = fadeOut() + shrinkVertically { 0 } + ) { + FlakerPrefsDialog( + onDismissRequest = viewModel::closePrefs, + onConfirmAction = viewModel::updatePrefs, + currentValues = state.currentPrefs, + ) } } } diff --git a/flaker-android-retrofit/src/main/java/io/rotlabs/flakerandroidretrofit/ui/FlakerPrefsUiDto.kt b/flaker-android-retrofit/src/main/java/io/rotlabs/flakerandroidretrofit/ui/FlakerPrefsUiDto.kt index 415261f..b9c4a76 100644 --- a/flaker-android-retrofit/src/main/java/io/rotlabs/flakerandroidretrofit/ui/FlakerPrefsUiDto.kt +++ b/flaker-android-retrofit/src/main/java/io/rotlabs/flakerandroidretrofit/ui/FlakerPrefsUiDto.kt @@ -4,4 +4,12 @@ data class FlakerPrefsUiDto( val delay: Int, val failPercent: Int, val variancePercent: Int, -) +) { + companion object { + val IMMATERIAL = FlakerPrefsUiDto( + delay = -1, + failPercent = -1, + variancePercent = -1 + ) + } +} diff --git a/flaker-android-retrofit/src/main/java/io/rotlabs/flakerandroidretrofit/ui/FlakerViewModel.kt b/flaker-android-retrofit/src/main/java/io/rotlabs/flakerandroidretrofit/ui/FlakerViewModel.kt index 3489e7d..4d7c868 100644 --- a/flaker-android-retrofit/src/main/java/io/rotlabs/flakerandroidretrofit/ui/FlakerViewModel.kt +++ b/flaker-android-retrofit/src/main/java/io/rotlabs/flakerandroidretrofit/ui/FlakerViewModel.kt @@ -33,13 +33,13 @@ class FlakerViewModel( data class ViewState( val isFlakerOn: Boolean = false, val networkRequests: List = emptyList(), - val currentPrefs: FlakerPrefsUiDto? = null, + val currentPrefs: FlakerPrefsUiDto = FlakerPrefsUiDto.IMMATERIAL, ) { val showNoRequests: Boolean get() = networkRequests.isEmpty() val toShowPrefs: Boolean - get() = currentPrefs != null + get() = currentPrefs != FlakerPrefsUiDto.IMMATERIAL } init { @@ -96,7 +96,11 @@ class FlakerViewModel( } fun closePrefs() { - viewModelScope.launch { _viewStateFlow.emit(_viewStateFlow.value.copy(currentPrefs = null)) } + viewModelScope.launch { + _viewStateFlow.emit( + _viewStateFlow.value.copy(currentPrefs = FlakerPrefsUiDto.IMMATERIAL) + ) + } } fun updatePrefs(flakerPrefsUiDto: FlakerPrefsUiDto) {