Skip to content

Instantly share code, notes, and snippets.

@alibahaaa
Created June 26, 2022 08:16
Show Gist options
  • Save alibahaaa/72166104ad9fa3262ed7d91f6478294a to your computer and use it in GitHub Desktop.
Save alibahaaa/72166104ad9fa3262ed7d91f6478294a to your computer and use it in GitHub Desktop.
import SwiftUI
import shared
struct ContentView: View {
let greet = Greeting().greeting()
@ObservedObject private var viewModel = ViewModel()
var body: some View {
VStack(){
NavigationView{
uiState()
.navigationTitle("KMM Origami")
}
}
.onAppear(){
viewModel.loadOrigamies()
}
}
private func uiState() -> AnyView {
switch viewModel.dataState {
case DataState.loading:
return AnyView( ZStack{
ProgressView()
.progressViewStyle(CircularProgressViewStyle(tint: .gray))
.scaleEffect(2)
}.multilineTextAlignment(.center))
case DataState.result(let origimies):
return AnyView(
List(origimies) { origimi in
NavigationLink {
DetailView(entity: origimi)
.navigationTitle(origimi.name)
} label: {
HomeView(entity: origimi)
}
}
)
case DataState.error:
return AnyView(Text("ERROR").multilineTextAlignment(.center))
}
}
}
extension Entity: Identifiable { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment