Skip to content

Latest commit

History

History
173 lines (129 loc) 路 5.55 KB

CHANGELOG.md

File metadata and controls

173 lines (129 loc) 路 5.55 KB

Change Log

Update dependencies

  • Kotlin 1.9.0.
  • AndroidX Lifecycle 2.6.1.
  • KotlinX Coroutines 1.7.3.
  • Android Gradle Plugin 8.1.0.

viewmodel

  • Add ViewModelStore and ViewModelStoreOwner.
  • Add ViewModelFactory and VIEW_MODEL_KEY.
  • Add CreationExtras and CreationExtrasKey.
  • Add buildCreationExtras and CreationExtras.edit.
  • Add ViewModel.isCleared() method to check if the ViewModel is cleared, only available on non-Android targets.
  • Add MainThread (moved from viewmodel-savedstate module).

viewmodel-savedstate

  • Remove MainThread (moved to viewmodel module).
  • Add SavedStateHandleFactory interface.
  • Add SAVED_STATE_HANDLE_FACTORY_KEY and CreationExtras.createSavedStateHandle().

viewmodel-compose

  • A new module allows to access ViewModels in Jetpack Compose Multiplatform.
    • kmpViewModel to retrieve ViewModels in @Composable functions.
    • LocalSavedStateHandleFactory and SavedStateHandleFactoryProvider to get/provide SavedStateHandleFactory in @Composable functions.
    • LocalViewModelStoreOwner and ViewModelStoreOwnerProvider to get/provide ViewModelStoreOwner in @Composable functions.
    • defaultPlatformCreationExtras and defaultPlatformViewModelStoreOwner to get the default CreationExtras and ViewModelStoreOwner, that depend on the platform.

0.4.0 - Apr 7, 2023

Changed

Update dependencies

  • Kotlin 1.8.10.
  • Target Java 11.
  • Touchlab Stately 1.2.5.
  • AndroidX Lifecycle 2.6.0.
  • Android Gradle Plugin 7.4.2.

Flow wrappers

  • Add NonNullStateFlowWrapper and NullableFlowWrapper to common source set.

  • Move all Flow wrappers to common source set. Previously, they were only available for Darwin targets (iOS, macOS, tvOS, watchOS).

  • Add Flow.wrap() extension methods to wrap Flows 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() }
    }

Example, docs and tests

  • Refactor example code.
  • Add more docs: 0.x docs.
  • Add more tests.

0.3.0 - Mar 18, 2023

Added

  • Add NonNullFlowWrapper and NullableFlowWrapper, that are wrappers for Flows that provides a more convenient API for subscribing to the Flows on Darwin targets (iOS , macOS, tvOS, watchOS)
    // Kotlin code
    val flow: StateFlow<Int>
    // Swift code
    NonNullFlowWrapper<KotlinInt>(flow: flow).subscribe(
      scope: scope,
      onValue: { print("Received ", $0) }
    )

Changed

  • 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

Added

Changed

  • Add more example, refactor example code.
  • Add more docs: 0.x docs.

0.1.0 - Feb 18, 2023

Changed

  • Make ViewModel.viewModelScope public.

Added

  • Add an ViewModel.addCloseable API and a new constructor overload constructor(vararg closeables: Closeable), that allow you to add one or more Closeable objects to the ViewModel that will be closed when the ViewModel is cleared without requiring any manual work in onCleared().

0.0.1 - Feb 11, 2023

  • Initial release.