NCCapabilitiesView.swift 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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() {
  18. capabililies = [Capability(text: "File sharing", image: UIImage(named: "share")!, available: true),
  19. Capability(text: "Externa site", image: UIImage(systemName: "network")!, available: false)
  20. ]
  21. }
  22. }
  23. struct NCCapabilitiesView: View {
  24. @ObservedObject var capabilitiesStatus: NCCapabilitiesStatus
  25. init(capabilitiesStatus: NCCapabilitiesStatus) {
  26. self.capabilitiesStatus = capabilitiesStatus
  27. }
  28. var body: some View {
  29. ScrollView {
  30. VStack {
  31. ForEach(capabilitiesStatus.capabililies, id: \.id) { capability in
  32. HStack {
  33. Capability(text: capability.text, image: Image(uiImage: capability.image))
  34. CapabilityAvailable(available: capability.available)
  35. }
  36. }
  37. }
  38. .frame(maxWidth: .infinity, alignment: .top)
  39. .padding(EdgeInsets(top: 20, leading: 10, bottom: 0, trailing: 10))
  40. }
  41. }
  42. }
  43. struct Capability: View {
  44. @State var text: String = ""
  45. @State var image: Image
  46. var body: some View {
  47. Label {
  48. Text(text)
  49. .font(.system(size: 15))
  50. .foregroundColor(Color(UIColor.systemGray))
  51. } icon: {
  52. image
  53. .renderingMode(.template)
  54. .resizable()
  55. .frame(width: 25.0, height: 25.0)
  56. .foregroundColor(Color(UIColor.systemGray))
  57. }
  58. .frame(maxWidth: .infinity, alignment: .leading)
  59. }
  60. }
  61. struct CapabilityAvailable: View {
  62. @State private var text: String
  63. init(available: Bool) {
  64. if available {
  65. _text = State(initialValue: NSLocalizedString("_available_", comment: ""))
  66. } else {
  67. _text = State(initialValue: NSLocalizedString("_not_available_", comment: ""))
  68. }
  69. }
  70. var body: some View {
  71. Text(text)
  72. .frame(width: 100)
  73. .font(.system(size: 12))
  74. .padding(EdgeInsets(top: 7, leading: 12, bottom: 7, trailing: 12))
  75. .foregroundColor(.primary)
  76. .background(
  77. RoundedRectangle(cornerRadius: 20)
  78. .stroke(Color(UIColor.systemGray), lineWidth: 0.5)
  79. .background(
  80. RoundedRectangle(cornerRadius: 20)
  81. .fill(Color(UIColor.secondarySystemBackground))
  82. )
  83. )
  84. .frame(maxWidth: .infinity, alignment: .trailing)
  85. }
  86. }
  87. struct NCCapabilitiesView_Previews: PreviewProvider {
  88. static var previews: some View {
  89. NCCapabilitiesView(capabilitiesStatus: NCCapabilitiesStatus())
  90. }
  91. }