multiplatform-viewmodel
0.0.3indexedFacilitates shared business logic through a `ViewModel` base class, leveraging Jetpack `ViewModel` on Android and exposing a `CoroutineScope` for method usage.
27
Stars
—
Used by
dependents
—
Health
/ 100
Facilitates shared business logic through a `ViewModel` base class, leveraging Jetpack `ViewModel` on Android and exposing a `CoroutineScope` for method usage.
Create shared ViewModel's for shared business logic using our ViewModel base class.
ViewModel on Android for lifecycledCoroutineScope to be used in your methodsThis package has 1 component to it:
A ViewModel class you can base your view models on.
Add Dependency
commonMain {
dependencies {
// ...
api("com.doublesymmetry:multiplatform-viewmodel:0.0.1")
}
}
Expose it to iOS native side
ios {
binaries {
framework {
baseName = "shared"
export(Deps.viewmodel) // required to expose the class to iOS
}
}
}
class ExampleViewModel: ViewModel() {
private val _viewState = MutableStateFlow(UIViewState())
val viewState: StateFlow<UIViewState> = _viewState
fun onLaunched() {
scope.launch {
// fetch some data
_viewState.emit(newState)
}
}
}
UIViewControllerWhen using it on iOS you'll want to make sure that you call clear() on your ViewModel on deinit to properly kill the CoroutineScope
Surfaced from shared tags and platforms — no rankings paid for.