- Kotlin
1.9.0
. - AndroidX Lifecycle
2.6.1
. - KotlinX Coroutines
1.7.3
. - Android Gradle Plugin
8.1.0
.
- Add
ViewModelStore
andViewModelStoreOwner
. - Add
ViewModelFactory
andVIEW_MODEL_KEY
. - Add
CreationExtras
andCreationExtrasKey
. - Add
buildCreationExtras
andCreationExtras.edit
. - Add
ViewModel.isCleared()
method to check if theViewModel
is cleared, only available on non-Android targets. - Add
MainThread
(moved fromviewmodel-savedstate
module).
- Remove
MainThread
(moved toviewmodel
module). - Add
SavedStateHandleFactory
interface. - Add
SAVED_STATE_HANDLE_FACTORY_KEY
andCreationExtras.createSavedStateHandle()
.
- A new module allows to access
ViewModel
s in Jetpack Compose Multiplatform.kmpViewModel
to retrieveViewModel
s in @Composable functions.LocalSavedStateHandleFactory
andSavedStateHandleFactoryProvider
to get/provideSavedStateHandleFactory
in @Composable functions.LocalViewModelStoreOwner
andViewModelStoreOwnerProvider
to get/provideViewModelStoreOwner
in @Composable functions.defaultPlatformCreationExtras
anddefaultPlatformViewModelStoreOwner
to get the defaultCreationExtras
andViewModelStoreOwner
, that depend on the platform.
0.4.0 - Apr 7, 2023
- Kotlin
1.8.10
. - Target
Java 11
. - Touchlab Stately
1.2.5
. - AndroidX Lifecycle
2.6.0
. - Android Gradle Plugin
7.4.2
.
-
Add
NonNullStateFlowWrapper
andNullableFlowWrapper
to common source set. -
Move all
Flow
wrappers to common source set. Previously, they were only available forDarwin targets
(iOS
,macOS
,tvOS
,watchOS
). -
Add
Flow.wrap()
extension methods to wrapFlow
s sources:Flow<T: Any>.wrap(): NonNullFlowWrapper<T>
.Flow<T>.wrap(): NullableFlowWrapper<T>
.StateFlow<T: Any>.wrap(): NonNullStateFlowWrapper<T>
.StateFlow<T>.wrap(): NullableStateFlowWrapper<T>
.
In common code, you can use these methods to wrap
Flow
sources and use them in Swift code easily.// Kotlin code data class State(...) class SharedViewModel : ViewModel() { private val _state = MutableStateFlow(State(...)) val stateFlow: NonNullStateFlowWrapper<State> = _state.wrap() }
// Swift code @MainActor class IosViewModel: ObservableObject { private let vm: SharedViewModel @Published private(set) var state: State init(viewModel: SharedViewModel) { vm = viewModel state = vm.stateFlow.value // <--- Use `value` property with type safety (do not need to cast). vm.stateFlow.subscribe( // <--- Use `subscribe(scope:onValue:)` method directly. scope: vm.viewModelScope, onValue: { [weak self] in self?.state = $0 } ) } deinit { vm.clear() } }
- Refactor example code.
- Add more docs: 0.x docs.
- Add more tests.
0.3.0 - Mar 18, 2023
- Add
NonNullFlowWrapper
andNullableFlowWrapper
, that are wrappers forFlow
s that provides a more convenient API for subscribing to theFlow
s onDarwin targets
(iOS
,macOS
,tvOS
,watchOS
)// Kotlin code val flow: StateFlow<Int>
// Swift code NonNullFlowWrapper<KotlinInt>(flow: flow).subscribe( scope: scope, onValue: { print("Received ", $0) } )
- Add more example, refactor example code.
- Add more docs: 0.x docs.
- Add more tests.
- Gradle
8.0.2
. - Dokka
1.8.10
.
0.2.0 - Mar 5, 2023
-
Add
kmp-viewmodel-savedstate
artifact. This artifact brings:- Android Parcelable interface.
- The
@Parcelize
annotation from kotlin-parcelize compiler plugin. - SavedStateHandle class.
to Kotlin Multiplatform, so they can be used in common code. This is typically used for state/data preservation over Android configuration changes and system-initiated process death , when writing common code targeting Android.
- Add more example, refactor example code.
- Add more docs: 0.x docs.
0.1.0 - Feb 18, 2023
- Make
ViewModel.viewModelScope
public.
- Add an
ViewModel.addCloseable
API and a new constructor overloadconstructor(vararg closeables: Closeable)
, that allow you to add one or moreCloseable
objects to theViewModel
that will be closed when theViewModel
is cleared without requiring any manual work inonCleared()
.
0.0.1 - Feb 11, 2023
- Initial release.