Basic redux setup for kotlin multiplatform with JetPack Compose and SwiftUI. AppStore can be derived into sub store.
- kotlinx coroutines
- kotlinx serialization
- ktor
- KSwift
- KMP Native coroutines
CounterStore usage on Jetpack Compose
@Composable
fun CounterView() {
val state by CounterStore.current.state.collectAsState()
val dispatch = CounterStore.current.dispatch
Column(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(20.dp, Alignment.CenterVertically)
) {
Text(text = "$state")
Row(horizontalArrangement = Arrangement.spacedBy(50.dp)) {
Button(onClick = {
dispatch(CounterAction.Increment)
}) {
Text(text = "+")
}
Button(onClick = {
dispatch(CounterAction.Decrement)
}) {
Text(text = "-")
}
}
}
}
CounterStore usage on SwiftUI
struct CounterView: View {
@EnvironmentObject private var store: CounterStore
var body: some View {
return VStack(spacing: 20) {
Text("\(store.state)")
HStack(spacing: 50) {
Button("+") {
store.dispatch(.increment)
}
Button("-") {
store.dispatch(.decrement)
}
}
}
}
}
- SpaceStore inspired from KMP Mobile Template
- SwiftUI AppStore inspired from swiftui-recipes-app