- Kotlin
1.9.0. - AndroidX Lifecycle
2.6.1. - KotlinX Coroutines
1.7.3. - Android Gradle Plugin
8.1.0.
- Add
ViewModelStoreandViewModelStoreOwner. - Add
ViewModelFactoryandVIEW_MODEL_KEY. - Add
CreationExtrasandCreationExtrasKey. - Add
buildCreationExtrasandCreationExtras.edit. - Add
ViewModel.isCleared()method to check if theViewModelis cleared, only available on non-Android targets. - Add
MainThread(moved fromviewmodel-savedstatemodule).
- Remove
MainThread(moved toviewmodelmodule). - Add
SavedStateHandleFactoryinterface. - Add
SAVED_STATE_HANDLE_FACTORY_KEYandCreationExtras.createSavedStateHandle().
- A new module allows to access
ViewModels in Jetpack Compose Multiplatform.kmpViewModelto retrieveViewModels in @Composable functions.LocalSavedStateHandleFactoryandSavedStateHandleFactoryProviderto get/provideSavedStateHandleFactoryin @Composable functions.LocalViewModelStoreOwnerandViewModelStoreOwnerProviderto get/provideViewModelStoreOwnerin @Composable functions.defaultPlatformCreationExtrasanddefaultPlatformViewModelStoreOwnerto get the defaultCreationExtrasandViewModelStoreOwner, 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
NonNullStateFlowWrapperandNullableFlowWrapperto common source set. -
Move all
Flowwrappers to common source set. Previously, they were only available forDarwin targets(iOS,macOS,tvOS,watchOS). -
Add
Flow.wrap()extension methods to wrapFlows 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
Flowsources 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
NonNullFlowWrapperandNullableFlowWrapper, that are wrappers forFlows that provides a more convenient API for subscribing to theFlows 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-savedstateartifact. This artifact brings:- Android Parcelable interface.
- The
@Parcelizeannotation 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.viewModelScopepublic.
- Add an
ViewModel.addCloseableAPI and a new constructor overloadconstructor(vararg closeables: Closeable), that allow you to add one or moreCloseableobjects to theViewModelthat will be closed when theViewModelis cleared without requiring any manual work inonCleared().
0.0.1 - Feb 11, 2023
- Initial release.