ContactTrickDetailView.swift 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. import SwiftUI
  2. struct ContactTrickDetailView: View {
  3. @Environment(\.dismiss) var dismiss
  4. @Environment(\.colorScheme) var colorScheme
  5. @Environment(AppState.self) var appState
  6. @ObservedObject var state: ContactTrick.StateModel
  7. @State private var contactTrickEntry: ContactTrickEntry
  8. init(entry: ContactTrickEntry, state: ContactTrick.StateModel) {
  9. self.state = state
  10. _contactTrickEntry = State(initialValue: entry)
  11. }
  12. var body: some View {
  13. VStack {
  14. HStack {
  15. // TODO: - make this beautiful @Dan
  16. Spacer()
  17. ZStack {
  18. Circle()
  19. .fill(contactTrickEntry.darkMode ? .black : .white)
  20. .foregroundColor(.white)
  21. .frame(width: 100, height: 100)
  22. Image(uiImage: ContactPicture.getImage(contact: contactTrickEntry, state: state.previewState))
  23. .resizable()
  24. .frame(width: 100, height: 100)
  25. .clipShape(Circle())
  26. Circle()
  27. .stroke(lineWidth: 2)
  28. .foregroundColor(.white)
  29. .frame(width: 100, height: 100)
  30. }
  31. Spacer()
  32. }
  33. .padding(.top, 80)
  34. .padding(.bottom)
  35. Form {
  36. Section(header: Text("Style")) {
  37. Picker("Layout", selection: $contactTrickEntry.layout) {
  38. ForEach(ContactTrickLayout.allCases, id: \.id) { layout in
  39. Text(layout.displayName).tag(layout)
  40. }
  41. }
  42. Toggle("Dark Mode", isOn: $contactTrickEntry.darkMode)
  43. }.listRowBackground(Color.chart)
  44. Section(header: Text("Display Values")) {
  45. if contactTrickEntry.layout == .single {
  46. Picker("Primary", selection: $contactTrickEntry.primary) {
  47. ForEach(ContactTrickValue.allCases, id: \.id) { value in
  48. Text(value.displayName).tag(value)
  49. }
  50. }
  51. }
  52. Picker("Top Value", selection: $contactTrickEntry.top) {
  53. ForEach(ContactTrickValue.allCases, id: \.id) { value in
  54. Text(value.displayName).tag(value)
  55. }
  56. }
  57. Picker("Bottom Value", selection: $contactTrickEntry.bottom) {
  58. ForEach(ContactTrickValue.allCases, id: \.id) { value in
  59. Text(value.displayName).tag(value)
  60. }
  61. }
  62. }.listRowBackground(Color.chart)
  63. if contactTrickEntry.ring != .none {
  64. Section(header: Text("Ring Settings")) {
  65. Picker("Ring Width", selection: $contactTrickEntry.ringWidth) {
  66. ForEach(ContactTrickEntry.RingWidth.allCases, id: \.self) { width in
  67. Text(width.displayName)
  68. .tag(width)
  69. }
  70. }
  71. Picker("Ring Gap", selection: $contactTrickEntry.ringGap) {
  72. ForEach(ContactTrickEntry.RingGap.allCases, id: \.self) { gap in
  73. Text(gap.displayName)
  74. .tag(gap)
  75. }
  76. }
  77. }.listRowBackground(Color.chart)
  78. }
  79. // Font Settings Section
  80. Section(header: Text("Font Settings")) {
  81. fontSizePicker
  82. secondaryFontSizePicker
  83. fontWeightPicker
  84. fontWidthPicker
  85. }.listRowBackground(Color.chart)
  86. }
  87. }
  88. .navigationTitle("Edit Contact Items")
  89. .navigationBarTitleDisplayMode(.inline)
  90. .safeAreaInset(edge: .bottom, spacing: 0) { stickySaveButton }
  91. .listSectionSpacing(10)
  92. .padding(.top, 30)
  93. .ignoresSafeArea(edges: .top)
  94. .scrollContentBackground(.hidden)
  95. .background(appState.trioBackgroundColor(for: colorScheme))
  96. .toolbar {
  97. ToolbarItem(placement: .topBarTrailing) {
  98. Button(
  99. action: {
  100. state.isHelpSheetPresented.toggle()
  101. },
  102. label: {
  103. Image(systemName: "questionmark.circle")
  104. }
  105. )
  106. }
  107. }
  108. .sheet(isPresented: $state.isHelpSheetPresented) {
  109. NavigationStack {
  110. List {
  111. Text("Lorem Ipsum Dolor Sit Amet")
  112. }
  113. .padding(.trailing, 10)
  114. .navigationBarTitle("Help", displayMode: .inline)
  115. Button { state.isHelpSheetPresented.toggle() }
  116. label: { Text("Got it!").frame(maxWidth: .infinity, alignment: .center) }
  117. .buttonStyle(.bordered)
  118. .padding(.top)
  119. }
  120. .padding()
  121. .presentationDetents(
  122. [.fraction(0.9), .large],
  123. selection: $state.helpSheetDetent
  124. )
  125. }
  126. }
  127. private func saveChanges() {
  128. Task {
  129. await state.updateContact(with: contactTrickEntry)
  130. dismiss()
  131. }
  132. }
  133. var stickySaveButton: some View {
  134. ZStack {
  135. Rectangle()
  136. .frame(width: UIScreen.main.bounds.width, height: 65)
  137. .foregroundStyle(colorScheme == .dark ? Color.bgDarkerDarkBlue : Color.white)
  138. .background(.thinMaterial)
  139. .opacity(0.8)
  140. .clipShape(Rectangle())
  141. Button(action: {
  142. saveChanges()
  143. }, label: {
  144. Text("Save").padding(10)
  145. })
  146. .frame(width: UIScreen.main.bounds.width * 0.9, alignment: .center)
  147. .background(Color(.systemBlue))
  148. .tint(.white)
  149. .clipShape(RoundedRectangle(cornerRadius: 8))
  150. .padding(5)
  151. }
  152. }
  153. private var fontSizePicker: some View {
  154. Picker("Font Size", selection: $contactTrickEntry.fontSize) {
  155. ForEach(ContactTrickEntry.FontSize.allCases, id: \.self) { size in
  156. Text(size.displayName).tag(size)
  157. }
  158. }
  159. }
  160. private var secondaryFontSizePicker: some View {
  161. Picker("Secondary Font Size", selection: $contactTrickEntry.secondaryFontSize) {
  162. ForEach(ContactTrickEntry.FontSize.allCases, id: \.self) { size in
  163. Text(size.displayName).tag(size)
  164. }
  165. }
  166. }
  167. private var fontWeightPicker: some View {
  168. Picker("Font Weight", selection: $contactTrickEntry.fontWeight) {
  169. ForEach(
  170. [Font.Weight.light, Font.Weight.regular, Font.Weight.medium, Font.Weight.bold, Font.Weight.black],
  171. id: \.self
  172. ) { weight in
  173. Text("\(weight.displayName)".capitalized).tag(weight)
  174. }
  175. }
  176. }
  177. private var fontWidthPicker: some View {
  178. Picker("Font Width", selection: $contactTrickEntry.fontWidth) {
  179. ForEach(
  180. [Font.Width.standard, Font.Width.condensed, Font.Width.expanded],
  181. id: \.self
  182. ) { width in
  183. Text("\(width.displayName)".capitalized).tag(width)
  184. }
  185. }
  186. }
  187. }