Няма описание

DiscoverView.swift 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // DiscoverView.swift
  3. // Flowerdex
  4. //
  5. // Created by Víctor A. Hernández on 10/25/20.
  6. //
  7. import SwiftUI
  8. struct DiscoverView: View {
  9. @EnvironmentObject var fModel: FlowerService
  10. @State var showingFilterPane: Bool = false
  11. @State var page: Int = 1
  12. // Filter Variables
  13. @State var edible: Bool = false
  14. @State var vegetable: Bool = false
  15. @State var petalCount: Int = 0
  16. @State var growthMonths: Int = 0
  17. @State var bloomMonths: Int = 0
  18. @State var scientificName: String = ""
  19. @State var commonName: String = ""
  20. init() {
  21. // FROM: https://sarunw.com/posts/uinavigationbar-changes-in-ios13/
  22. let appearance = UINavigationBarAppearance()
  23. appearance.titleTextAttributes = [.foregroundColor: UIColor(Constants.Colors.blueGray)] // small, collapsed title
  24. appearance.largeTitleTextAttributes = [.foregroundColor: UIColor(Constants.Colors.rausch)] // large title
  25. // UINavigationBar.appearance().scrollEdgeAppearance = appearance
  26. UINavigationBar.appearance().standardAppearance = appearance
  27. }
  28. var body: some View {
  29. NavigationView {
  30. ScrollView {
  31. ScrollableSearchedContent()
  32. }
  33. .navigationBarTitle("Discover")
  34. .navigationBarItems(trailing:
  35. Button(action: {self.showingFilterPane = true}) {
  36. FilterButtonIcon()
  37. }
  38. .sheet(isPresented: $showingFilterPane, content: {
  39. FiltersSheet(showingFilterPane: $showingFilterPane, page: $page, edible: $edible, vegetable: $vegetable, petalCount: $petalCount, growthMonths: $growthMonths, bloomMonths: $bloomMonths, scientificName: $scientificName, commonName: $commonName)
  40. })
  41. )
  42. }
  43. .onAppear {
  44. self.fModel.getFlowers(p: page, f: nil)
  45. }
  46. }
  47. }
  48. struct ScrollableSearchedContent: View {
  49. @EnvironmentObject var fModel: FlowerService
  50. var body: some View {
  51. if fModel.response == .success {
  52. FlowersList(flowerList: fModel.items)
  53. } else if fModel.response == .loading || fModel.response == .unfetched {
  54. // TODO: make this centered vertically within parent ScrollView
  55. ProgressView("Loading...")
  56. } else if fModel.response == .failure {
  57. // TODO: make this centered vertically within parent ScrollView
  58. FailureIcon()
  59. }
  60. }
  61. }
  62. struct FilterButtonIcon: View {
  63. var body: some View {
  64. Image(systemName: "slider.horizontal.3")
  65. .font(.title)
  66. .foregroundColor(Constants.Colors.rausch)
  67. }
  68. }