
Sealed state types modeling common UI transitions — loading, saving, mutating (with original/updated tracking), plus ResourceState that combines load/save flows for predictable, type-safe view-state handling.
A Kotlin Multiplatform library for managing common UI state transitions.
The viewing-state-kmp package provides sealed classes to handle common view state transitions:
LoadState — Idle, Loading, Loaded, FailureSaveState — Idle, Saving, Saved, FailureMutationState — Idle, Mutating, Mutated, Failure (with original/updated tracking)ResourceState — Idle, Loading, Loaded, LoadFailure, Saving, Saved, SaveFailureAdd the Maven Central repository to your settings.gradle.kts (if not already present):
dependencyResolutionManagement {
repositories {
mavenCentral()
}
}Then add the dependency to your build.gradle.kts:
implementation("com.felipearpa:viewing-state:1.0.0")class MyViewModel : ViewModel() {
private val _state = MutableStateFlow<LoadState<MyData>>(LoadState.Idle)
val state: StateFlow<LoadState<MyData>> = _state.asStateFlow()
fun fetchData() {
viewModelScope.launch {
_state.value = LoadState.Loading
try {
val result = repository.fetchData()
_state.value = LoadState.Loaded(result)
} catch (exception: Exception) {
_state.value = LoadState.Failure(exception)
}
}
}
}Full documentation is available at the project site.
If you would like to contribute, please open a pull request or submit an issue. We are happy to review your changes or ideas!
This project is licensed under the MIT License.
A Kotlin Multiplatform library for managing common UI state transitions.
The viewing-state-kmp package provides sealed classes to handle common view state transitions:
LoadState — Idle, Loading, Loaded, FailureSaveState — Idle, Saving, Saved, FailureMutationState — Idle, Mutating, Mutated, Failure (with original/updated tracking)ResourceState — Idle, Loading, Loaded, LoadFailure, Saving, Saved, SaveFailureAdd the Maven Central repository to your settings.gradle.kts (if not already present):
dependencyResolutionManagement {
repositories {
mavenCentral()
}
}Then add the dependency to your build.gradle.kts:
implementation("com.felipearpa:viewing-state:1.0.0")class MyViewModel : ViewModel() {
private val _state = MutableStateFlow<LoadState<MyData>>(LoadState.Idle)
val state: StateFlow<LoadState<MyData>> = _state.asStateFlow()
fun fetchData() {
viewModelScope.launch {
_state.value = LoadState.Loading
try {
val result = repository.fetchData()
_state.value = LoadState.Loaded(result)
} catch (exception: Exception) {
_state.value = LoadState.Failure(exception)
}
}
}
}Full documentation is available at the project site.
If you would like to contribute, please open a pull request or submit an issue. We are happy to review your changes or ideas!
This project is licensed under the MIT License.