NCCapabilitiesView.swift 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // NCCapabilitiesView.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 19/05/23.
  6. // Copyright © 2023 Marino Faggiana. All rights reserved.
  7. //
  8. import SwiftUI
  9. class NCCapabilitiesStatus: ObservableObject {
  10. struct Capability: Identifiable, Hashable {
  11. let id = UUID()
  12. let text: String
  13. let image: UIImage
  14. let available: Bool
  15. }
  16. @Published var capabililies: [Capability] = []
  17. init(preview: Bool = false) {
  18. if preview {
  19. capabililies = [Capability(text: "File sharing", image: UIImage(named: "share")!, available: true),
  20. Capability(text: "Externa site", image: UIImage(systemName: "network")!, available: false)
  21. ]
  22. }
  23. }
  24. }
  25. struct NCCapabilitiesView: View {
  26. @ObservedObject var capabilitiesStatus: NCCapabilitiesStatus
  27. init(capabilitiesStatus: NCCapabilitiesStatus) {
  28. self.capabilitiesStatus = capabilitiesStatus
  29. }
  30. var body: some View {
  31. ScrollView {
  32. VStack {
  33. ForEach(capabilitiesStatus.capabililies, id: \.id) { capability in
  34. HStack {
  35. Capability(text: capability.text, image: Image(uiImage: capability.image))
  36. CapabilityAvailable(available: capability.available)
  37. }
  38. }
  39. }
  40. .frame(maxWidth: .infinity, alignment: .top)
  41. .padding(EdgeInsets(top: 20, leading: 10, bottom: 0, trailing: 10))
  42. }
  43. }
  44. }
  45. struct Capability: View {
  46. @State var text: String = ""
  47. @State var image: Image
  48. var body: some View {
  49. Label {
  50. Text(text)
  51. .font(.system(size: 15))
  52. .foregroundColor(Color(UIColor.systemGray))
  53. } icon: {
  54. image
  55. .renderingMode(.template)
  56. .resizable()
  57. .frame(width: 25.0, height: 25.0)
  58. .foregroundColor(Color(UIColor.systemGray))
  59. }
  60. .frame(maxWidth: .infinity, alignment: .leading)
  61. }
  62. }
  63. struct CapabilityAvailable: View {
  64. @State private var text: String
  65. init(available: Bool) {
  66. if available {
  67. _text = State(initialValue: NSLocalizedString("_available_", comment: ""))
  68. } else {
  69. _text = State(initialValue: NSLocalizedString("_not_available_", comment: ""))
  70. }
  71. }
  72. var body: some View {
  73. Text(text)
  74. .frame(width: 100)
  75. .font(.system(size: 12))
  76. .padding(EdgeInsets(top: 7, leading: 12, bottom: 7, trailing: 12))
  77. .foregroundColor(.primary)
  78. .background(
  79. RoundedRectangle(cornerRadius: 20)
  80. .stroke(Color(UIColor.systemGray), lineWidth: 0.5)
  81. .background(
  82. RoundedRectangle(cornerRadius: 20)
  83. .fill(Color(UIColor.secondarySystemBackground))
  84. )
  85. )
  86. .frame(maxWidth: .infinity, alignment: .trailing)
  87. }
  88. }
  89. struct NCCapabilitiesView_Previews: PreviewProvider {
  90. static var previews: some View {
  91. NCCapabilitiesView(capabilitiesStatus: NCCapabilitiesStatus(preview: true))
  92. }
  93. }