https://github.com/galex/yamvil
Yamvil is a runtime library and compiler plugin to help Android Developers write Screens that adhere to the MVI Pattern.
https://github.com/galex/yamvil
android kotlin kotlin-multiplatform kotlin-multiplatform-library mvi mvi-android mvi-architecture
Last synced: 6 months ago
JSON representation
Yamvil is a runtime library and compiler plugin to help Android Developers write Screens that adhere to the MVI Pattern.
- Host: GitHub
- URL: https://github.com/galex/yamvil
- Owner: galex
- License: apache-2.0
- Created: 2024-05-11T10:16:05.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-22T05:33:07.000Z (over 1 year ago)
- Last Synced: 2024-05-23T06:34:58.318Z (over 1 year ago)
- Topics: android, kotlin, kotlin-multiplatform, kotlin-multiplatform-library, mvi, mvi-android, mvi-architecture
- Language: Kotlin
- Homepage: https://docs.galex.dev/yamvil
- Size: 285 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Yamvil
[](https://central.sonatype.com/search?q=dev.galex.yamvil)
[](https://github.com/galex/yamvil/actions/workflows/ci.yml)
[](https://codecov.io/github/galex/yamvil)
[](https://opensource.org/licenses/Apache-2.0)
Yamvil is a library and a compiler plugin bringing MVI Infrastructure to ViewModels, Fragments and Jetpack Compose, for Android and Compose Multiplatform apps.
> ⚠️ **This is a work in progress**: Yamvil is still in early development and is not ready for production use. The API is subject to change and only Android Studio Nightly shows the errors thrown by the compiler plugin.
## Documentation
The full documentation of Yamvil [is available here](https://docs.galex.dev/yamvil/).
## To the Point
Write MVI ViewModels like this:
```kotlin
class DashboardViewModel: MVIViewModel() {
override fun initializeUiState(): DashboardUiState {
return DashboardUiState(state = DashboardUiState.ContentState.Loading)
}
override fun handleEvent(event: DashboardUiEvent) {
when (event) {
is DashboardUiEvent.ClickOnNext -> onClickOnNext()
}
}
private fun onClickOnNext() {
update { copy(action = Consumable(DashboardUiAction.NavigateToNext)) }
}
}
```
Then use your MVI ViewModel in a Composable like this:
```kotlin
@Composable
fun DashboardScreen(
uiState: DashboardUiState,
handleEvent: (DashboardUiEvent) -> Unit,
modifier: Modifier = Modifier
) {
when (uiState.state) {
is DashboardUiState.ContentState.Loading -> DashboardLoadingContent()
is DashboardUiState.ContentState.Error -> DashboardErrorContent()
is DashboardUiState.ContentState.Content -> DashboardContent(uiState.state)
}
LaunchedActionEffect(uiState) { action: DashboardUiAction ->
when (action) {
DashboardUiAction.NavigateToNext -> {}
}
}
}
// (...)
```
Or if you're using Fragments, like this:
```kotlin
class DashboardFragment: MVIFragment() {
override val viewModel: DashboardViewModel by viewModels()
override fun observeUiState(uiState: DashboardUiState) {
when (uiState.state) {
DashboardUiState.ContentState.Loading -> onLoading()
is DashboardUiState.ContentState.Content -> onContent(uiState.state)
DashboardUiState.ContentState.Error -> onError()
}
uiState.onAction { action ->
when (action) {
DashboardUiAction.NavigateToNext -> navigateToNext()
}
}
}
// (...)
}
```
## Installation
In your libs.version.toml, add the following:
```toml
[versions]
yamvil = "0.0.2"
[libraries]
yamvil = { group = "dev.galex.yamvil", name = "runtime", version.ref = "yamvil" }
[plugins]
yamvil = { id = "dev.galex.yamvil", version.ref = "yamvil" }
```
Then add those to your project:
```kotlin
// Root build.gradle.kts
plugins {
alias(libs.plugins.yamvil) apply false
}
// In your app/build.gradle.kts
plugins {
alias(libs.plugins.yamvil)
}
dependencies {
implementation(libs.yamvil)
}
```
## Configuration
```kotlin
yamvil {
level = YamvilLevel.Error // or Warning
compose {
screenSuffix = "Screen"
uiStateParameterName = "uiState"
handleEventParameterMame = "onEvent"
}
}
```
## Publishing
Run `./gradlew publishToMavenLocal` to publish all the artefacts locally.
Run `./gradlew publishAndReleaseToMavenCentral --no-configuration-cache` to publish all artefacts to Maven Central.