Migrate to AndroidX ViewModel from Voyager ScreenModel (#3594)
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
plugins {
|
||||
alias(mihonx.plugins.android.library)
|
||||
alias(mihonx.plugins.spotless)
|
||||
|
||||
alias(libs.plugins.kotlin.serialization)
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "mihon.core.viewmodel"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.androidx.lifecycle.viewmodel)
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest />
|
||||
@@ -0,0 +1,11 @@
|
||||
package mihon.core.viewmodel
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
|
||||
abstract class StateViewModel<S>(initialState: S) : ViewModel() {
|
||||
protected val mutableState: MutableStateFlow<S> = MutableStateFlow(initialState)
|
||||
val state: StateFlow<S> = mutableState.asStateFlow()
|
||||
}
|
||||
Reference in New Issue
Block a user