Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AnimatedVisibility for opening full screen prefs dialog #37

Merged
merged 1 commit into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ class FlakerViewModel(
data class ViewState(
val isFlakerOn: Boolean = false,
val networkRequests: List<NetworkRequestUi> = 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 {
Expand Down Expand Up @@ -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) {
Expand Down