Ei kuvausta

SearchContainer.swift 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // SearchContainer.swift
  3. // Comedores Sociales
  4. //
  5. // Created by Hector Carrion on 11/30/20.
  6. //
  7. import SwiftUI
  8. struct SearchContainer: View {
  9. @State var filteredItems = foods
  10. @State var showingProfile: Bool = false
  11. @EnvironmentObject var profileVM: ProfileViewModel
  12. @State var hideButton = false
  13. @State var disableButton = false
  14. var body: some View {
  15. ZStack(alignment: .topTrailing) {
  16. CustomNavigationView(view: AnyView(Search(filteredItems: $filteredItems)), placeHolder: NSLocalizedString("search", comment:""), largeTitle: true, title: NSLocalizedString("inventory", comment:""),
  17. onSearch: { (txt) in
  18. // filterting Data...
  19. if txt != ""{
  20. self.filteredItems = foods.filter{$0.name.lowercased().contains(txt.lowercased())}
  21. }
  22. else{
  23. self.filteredItems = foods
  24. }
  25. }, onCancel: {
  26. // Do Your Own Code When Search And Canceled....
  27. self.filteredItems = foods
  28. self.hideButton = false
  29. self.disableButton = false
  30. }, onClick: {
  31. self.hideButton = true
  32. self.disableButton = true
  33. })
  34. .ignoresSafeArea()
  35. Button(action: {
  36. self.showingProfile.toggle()
  37. let token = UserToken(token: UserDefaults.standard.string(forKey: "token")!)
  38. profileVM.fetchMember(token: token)
  39. }) {
  40. Image(systemName: "person.crop.circle")
  41. .font(.system(size: 30))
  42. .opacity(hideButton ? 0 : 1)
  43. }.disabled(disableButton)
  44. .offset(x: 0, y: -10)
  45. .padding()
  46. .sheet(isPresented: $showingProfile, content: {ProfileView()})
  47. }
  48. }
  49. }
  50. struct SearchContainer_Previews: PreviewProvider {
  51. static var previews: some View {
  52. SearchContainer()
  53. }
  54. }