diff --git a/TabBarProject.xcodeproj/project.pbxproj b/TabBarProject.xcodeproj/project.pbxproj index f00780a..a7c092b 100644 --- a/TabBarProject.xcodeproj/project.pbxproj +++ b/TabBarProject.xcodeproj/project.pbxproj @@ -13,6 +13,8 @@ FAA868CA261C5A42000DEDDA /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FAA868C9261C5A42000DEDDA /* Preview Assets.xcassets */; }; FAA868D5261C5A42000DEDDA /* TabBarProjectTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA868D4261C5A42000DEDDA /* TabBarProjectTests.swift */; }; FAA868E0261C5A42000DEDDA /* TabBarProjectUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA868DF261C5A42000DEDDA /* TabBarProjectUITests.swift */; }; + FAA86902261C5F3E000DEDDA /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA86901261C5F3E000DEDDA /* SettingsView.swift */; }; + FAA86916261C63EA000DEDDA /* ListCategoryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA86915261C63EA000DEDDA /* ListCategoryView.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -45,6 +47,8 @@ FAA868DB261C5A42000DEDDA /* TabBarProjectUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TabBarProjectUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; FAA868DF261C5A42000DEDDA /* TabBarProjectUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarProjectUITests.swift; sourceTree = ""; }; FAA868E1261C5A42000DEDDA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + FAA86901261C5F3E000DEDDA /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = ""; }; + FAA86915261C63EA000DEDDA /* ListCategoryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListCategoryView.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -72,6 +76,15 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + FA2C7356261C68B100EB7C44 /* Views */ = { + isa = PBXGroup; + children = ( + FAA86901261C5F3E000DEDDA /* SettingsView.swift */, + FAA86915261C63EA000DEDDA /* ListCategoryView.swift */, + ); + path = Views; + sourceTree = ""; + }; FAA868B6261C5A41000DEDDA = { isa = PBXGroup; children = ( @@ -95,6 +108,7 @@ FAA868C1261C5A41000DEDDA /* TabBarProject */ = { isa = PBXGroup; children = ( + FA2C7356261C68B100EB7C44 /* Views */, FAA868C2261C5A41000DEDDA /* TabBarProjectApp.swift */, FAA868C4261C5A41000DEDDA /* ContentView.swift */, FAA868C6261C5A42000DEDDA /* Assets.xcassets */, @@ -259,7 +273,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + FAA86902261C5F3E000DEDDA /* SettingsView.swift in Sources */, FAA868C5261C5A41000DEDDA /* ContentView.swift in Sources */, + FAA86916261C63EA000DEDDA /* ListCategoryView.swift in Sources */, FAA868C3261C5A41000DEDDA /* TabBarProjectApp.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/TabBarProject/ContentView.swift b/TabBarProject/ContentView.swift index e9691b8..ace5b88 100644 --- a/TabBarProject/ContentView.swift +++ b/TabBarProject/ContentView.swift @@ -7,10 +7,58 @@ import SwiftUI +class User: ObservableObject { + @Published var score = 0 +} + + struct ContentView: View { + @State private var isShowingDetailView = false + @ObservedObject var user = User() + var body: some View { - Text("Hello, world!") - .padding() + + NavigationView{ + TabView { + + ListCategoryView() + .tabItem { + Image(systemName: "phone.fill") + Text("First Tab") + } + + Text("The content of the second view") + .tabItem { + Image(systemName: "tv.fill") + Text("Second Tab") + } + + Text("The content of the Third view") + .tabItem { + Image(systemName: "circle.fill") + Text("Third Tab") + } + } + .navigationBarItems( + trailing: HStack { + NavigationLink(destination: SettingsView(), isActive: $isShowingDetailView){ + EmptyView() + } + + Button("Settings"){ + isShowingDetailView.toggle() + } + } + + + ) + .navigationBarTitle("Logskills App") + .navigationBarTitleDisplayMode(.inline) + } + + // Important à ajouter + .environmentObject(user) + } } diff --git a/TabBarProject/Views/ListCategoryView.swift b/TabBarProject/Views/ListCategoryView.swift new file mode 100644 index 0000000..feaf5f3 --- /dev/null +++ b/TabBarProject/Views/ListCategoryView.swift @@ -0,0 +1,63 @@ +// +// ListCategoryView.swift +// TabBarProject +// +// Created by Arthur Dambrine on 06/04/2021. +// + +import SwiftUI + +struct Category: Codable, Identifiable { + let id = UUID() + let id_categorie: Int + let nom: String +} + +class apiCall { + func getCategories(completion:@escaping ([Category]) -> ()) { + guard let url = URL(string: "https://api.art-dambrine.ovh/categories") else { return } + URLSession.shared.dataTask(with: url) { (data, _, _) in + let categories = try! JSONDecoder().decode([Category].self, from: data!) + print(categories) + + DispatchQueue.main.async { + completion(categories) + } + } + .resume() + } +} + + +struct ListCategoryView: View { + @State var categories: [Category] = [] + + var body: some View { + VStack { + Button { + print("buttonClicked") + apiCall().getCategories { (categories) in + self.categories = categories + } + } label : { + Text("Afficher les categories") + } + + List(categories) { categorie in + + Text(String(categorie.id_categorie)) + .font(.headline) + Text(categorie.nom) + .font(.subheadline) + + } + + } + } +} + +struct ListCategoryView_Previews: PreviewProvider { + static var previews: some View { + ListCategoryView() + } +} diff --git a/TabBarProject/Views/SettingsView.swift b/TabBarProject/Views/SettingsView.swift new file mode 100644 index 0000000..06c18f8 --- /dev/null +++ b/TabBarProject/Views/SettingsView.swift @@ -0,0 +1,30 @@ +// +// SettingsView.swift +// TabBarProject +// +// Created by Arthur Dambrine on 06/04/2021. +// + +import SwiftUI + +struct SettingsView: View { + @EnvironmentObject var user: User + + var body: some View { + + VStack{ + Text("Ici on peut modifier les reglages") + + Text("Score : \(user.score)") + Button("Increase"){ + self.user.score += 1 + } + } + } +} + +struct SettingsView_Previews: PreviewProvider { + static var previews: some View { + SettingsView() + } +}