0.4.0
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
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() } }
Example, docs and tests
- Refactor example code.
- Add more docs: 0.x docs.
- Add more tests.