Created
June 26, 2022 08:16
-
-
Save alibahaaa/72166104ad9fa3262ed7d91f6478294a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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