|
|
@@ -2,15 +2,17 @@ import SwiftUI
|
|
|
|
|
|
struct AddContactTrickSheet: View {
|
|
|
@Environment(\.dismiss) var dismiss
|
|
|
- var state: ContactTrick.StateModel
|
|
|
+ @Environment(\.colorScheme) var colorScheme
|
|
|
+ @Environment(AppState.self) var appState
|
|
|
+
|
|
|
+ @ObservedObject var state: ContactTrick.StateModel
|
|
|
|
|
|
- @State private var name: String = ""
|
|
|
@State private var isDarkMode: Bool = false
|
|
|
@State private var ringWidth: ContactTrickEntry.RingWidth = .regular
|
|
|
@State private var ringGap: ContactTrickEntry.RingGap = .small
|
|
|
@State private var layout: ContactTrickLayout = .single
|
|
|
@State private var primary: ContactTrickValue = .glucose
|
|
|
- @State private var top: ContactTrickValue = .none
|
|
|
+ @State private var top: ContactTrickValue = .delta
|
|
|
@State private var bottom: ContactTrickValue = .none
|
|
|
@State private var ring: ContactTrickLargeRing = .none
|
|
|
@State private var fontSize: ContactTrickEntry.FontSize = .regular
|
|
|
@@ -21,7 +23,7 @@ struct AddContactTrickSheet: View {
|
|
|
private var previewEntry: ContactTrickEntry {
|
|
|
ContactTrickEntry(
|
|
|
id: UUID(),
|
|
|
- name: name,
|
|
|
+ name: "", // automatically set and populated
|
|
|
layout: layout,
|
|
|
ring: ring,
|
|
|
primary: primary,
|
|
|
@@ -40,96 +42,161 @@ struct AddContactTrickSheet: View {
|
|
|
|
|
|
var body: some View {
|
|
|
NavigationView {
|
|
|
- Form {
|
|
|
- // TODO: - make this beautiful @Dan
|
|
|
-
|
|
|
+ VStack {
|
|
|
// Preview Section
|
|
|
- Section {
|
|
|
- HStack {
|
|
|
- Spacer()
|
|
|
+ HStack {
|
|
|
+ Spacer()
|
|
|
+ ZStack {
|
|
|
+ Circle()
|
|
|
+ .fill(previewEntry.darkMode ? .black : .white)
|
|
|
+ .foregroundColor(.white)
|
|
|
+ .frame(width: 100, height: 100)
|
|
|
Image(uiImage: ContactPicture.getImage(contact: previewEntry, state: state.previewState))
|
|
|
.resizable()
|
|
|
- .aspectRatio(1, contentMode: .fit)
|
|
|
.frame(width: 100, height: 100)
|
|
|
.clipShape(Circle())
|
|
|
- .overlay(Circle().stroke(Color.gray, lineWidth: 1))
|
|
|
- Spacer()
|
|
|
+ Circle()
|
|
|
+ .stroke(lineWidth: 2)
|
|
|
+ .foregroundColor(.white)
|
|
|
+ .frame(width: 100, height: 100)
|
|
|
}
|
|
|
+ Spacer()
|
|
|
}
|
|
|
-
|
|
|
- // Name Section
|
|
|
- TextField("Name", text: $name)
|
|
|
-
|
|
|
- // Layout Section
|
|
|
- Section(header: Text("Layout")) {
|
|
|
- Toggle("Dark Mode", isOn: $isDarkMode)
|
|
|
- Picker("Layout", selection: $layout) {
|
|
|
- ForEach(ContactTrickLayout.allCases, id: \.id) { layout in
|
|
|
- Text(layout.displayName).tag(layout)
|
|
|
+ .padding(.top, 40)
|
|
|
+ .padding(.bottom)
|
|
|
+
|
|
|
+ Form {
|
|
|
+ // Layout Section
|
|
|
+ Section(header: Text("Style")) {
|
|
|
+ Picker("Layout", selection: $layout) {
|
|
|
+ ForEach(ContactTrickLayout.allCases, id: \.id) { layout in
|
|
|
+ Text(layout.displayName).tag(layout)
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- .pickerStyle(SegmentedPickerStyle())
|
|
|
- }
|
|
|
-
|
|
|
- // Primary Value Section
|
|
|
- Section(header: Text("Primary Value")) {
|
|
|
- Picker("Primary", selection: $primary) {
|
|
|
- ForEach(ContactTrickValue.allCases, id: \.id) { value in
|
|
|
- Text(value.displayName).tag(value)
|
|
|
+ Toggle("Dark Mode", isOn: $isDarkMode)
|
|
|
+ }.listRowBackground(Color.chart)
|
|
|
+
|
|
|
+ // Primary Value Section
|
|
|
+ Section(header: Text("Display Values")) {
|
|
|
+ if layout == .single {
|
|
|
+ Picker("Primary", selection: $primary) {
|
|
|
+ ForEach(ContactTrickValue.allCases, id: \.id) { value in
|
|
|
+ Text(value.displayName).tag(value)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- // Additional Values Section
|
|
|
- Section(header: Text("Additional Values")) {
|
|
|
- Picker("Top Value", selection: $top) {
|
|
|
- ForEach(ContactTrickValue.allCases, id: \.id) { value in
|
|
|
- Text(value.displayName).tag(value)
|
|
|
+ Picker("Top Value", selection: $top) {
|
|
|
+ ForEach(ContactTrickValue.allCases, id: \.id) { value in
|
|
|
+ Text(value.displayName).tag(value)
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- Picker("Bottom Value", selection: $bottom) {
|
|
|
- ForEach(ContactTrickValue.allCases, id: \.id) { value in
|
|
|
- Text(value.displayName).tag(value)
|
|
|
+ Picker("Bottom Value", selection: $bottom) {
|
|
|
+ ForEach(ContactTrickValue.allCases, id: \.id) { value in
|
|
|
+ Text(value.displayName).tag(value)
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- // Ring Settings Section
|
|
|
- Section(header: Text("Ring Settings")) {
|
|
|
- Picker("Ring Type", selection: $ring) {
|
|
|
- ForEach(ContactTrickLargeRing.allCases, id: \.self) { ring in
|
|
|
- Text(ring.displayName).tag(ring)
|
|
|
+ }.listRowBackground(Color.chart)
|
|
|
+
|
|
|
+ // Ring Settings Section
|
|
|
+ Section(header: Text("Ring Settings")) {
|
|
|
+ Picker("Ring Type", selection: $ring) {
|
|
|
+ ForEach(ContactTrickLargeRing.allCases, id: \.self) { ring in
|
|
|
+ Text(ring.displayName).tag(ring)
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- Picker("Ring Width", selection: $ringWidth) {
|
|
|
- ForEach(ContactTrickEntry.RingWidth.allCases, id: \.self) { width in
|
|
|
- Text(width.displayName).tag(width)
|
|
|
+
|
|
|
+ if ring != .none {
|
|
|
+ Picker("Ring Width", selection: $ringWidth) {
|
|
|
+ ForEach(ContactTrickEntry.RingWidth.allCases, id: \.self) { width in
|
|
|
+ Text(width.displayName).tag(width)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Picker("Ring Gap", selection: $ringGap) {
|
|
|
+ ForEach(ContactTrickEntry.RingGap.allCases, id: \.self) { gap in
|
|
|
+ Text(gap.displayName).tag(gap)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ }.listRowBackground(Color.chart)
|
|
|
+
|
|
|
+ // Font Settings Section
|
|
|
+ Section(header: Text("Font Settings")) {
|
|
|
+ fontSizePicker
|
|
|
+ secondaryFontSizePicker
|
|
|
+ fontWeightPicker
|
|
|
+ fontWidthPicker
|
|
|
+ }.listRowBackground(Color.chart)
|
|
|
+ }
|
|
|
+
|
|
|
+ stickySaveButton
|
|
|
+ }
|
|
|
+ .navigationTitle("Add Contact Items")
|
|
|
+ .navigationBarTitleDisplayMode(.inline)
|
|
|
+ .listSectionSpacing(10)
|
|
|
+ .padding(.top, 30)
|
|
|
+ .ignoresSafeArea(edges: .top)
|
|
|
+ .scrollContentBackground(.hidden)
|
|
|
+ .background(appState.trioBackgroundColor(for: colorScheme))
|
|
|
+ .toolbar {
|
|
|
+ ToolbarItem(placement: .topBarLeading) {
|
|
|
+ Button("Cancel") {
|
|
|
+ dismiss()
|
|
|
}
|
|
|
- Picker("Ring Gap", selection: $ringGap) {
|
|
|
- ForEach(ContactTrickEntry.RingGap.allCases, id: \.self) { gap in
|
|
|
- Text(gap.displayName).tag(gap)
|
|
|
+ }
|
|
|
+ ToolbarItem(placement: .topBarTrailing) {
|
|
|
+ Button(
|
|
|
+ action: {
|
|
|
+ state.isHelpSheetPresented.toggle()
|
|
|
+ },
|
|
|
+ label: {
|
|
|
+ Image(systemName: "questionmark.circle")
|
|
|
}
|
|
|
- }
|
|
|
+ )
|
|
|
}
|
|
|
+ }
|
|
|
+ .sheet(isPresented: $state.isHelpSheetPresented) {
|
|
|
+ NavigationStack {
|
|
|
+ List {
|
|
|
+ Text("Lorem Ipsum Dolor Sit Amet")
|
|
|
+ }
|
|
|
+ .padding(.trailing, 10)
|
|
|
+ .navigationBarTitle("Help", displayMode: .inline)
|
|
|
|
|
|
- // Font Settings Section
|
|
|
- Section(header: Text("Font Settings")) {
|
|
|
- fontSizePicker
|
|
|
- secondaryFontSizePicker
|
|
|
- fontWeightPicker
|
|
|
- fontWidthPicker
|
|
|
+ Button { state.isHelpSheetPresented.toggle() }
|
|
|
+ label: { Text("Got it!").frame(maxWidth: .infinity, alignment: .center) }
|
|
|
+ .buttonStyle(.bordered)
|
|
|
+ .padding(.top)
|
|
|
}
|
|
|
+ .padding()
|
|
|
+ .presentationDetents(
|
|
|
+ [.fraction(0.9), .large],
|
|
|
+ selection: $state.helpSheetDetent
|
|
|
+ )
|
|
|
}
|
|
|
- .navigationBarTitle("Add Contact Trick", displayMode: .inline)
|
|
|
- .navigationBarItems(
|
|
|
- leading: Button("Cancel") {
|
|
|
- dismiss()
|
|
|
- },
|
|
|
- trailing: Button("Save") {
|
|
|
- saveNewEntry()
|
|
|
- }
|
|
|
- )
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var stickySaveButton: some View {
|
|
|
+ ZStack {
|
|
|
+ Rectangle()
|
|
|
+ .frame(width: UIScreen.main.bounds.width, height: 65)
|
|
|
+ .foregroundStyle(colorScheme == .dark ? Color.bgDarkerDarkBlue : Color.white)
|
|
|
+ .background(.thinMaterial)
|
|
|
+ .opacity(0.8)
|
|
|
+ .clipShape(Rectangle())
|
|
|
+
|
|
|
+ Button(action: {
|
|
|
+ saveNewEntry()
|
|
|
+ }, label: {
|
|
|
+ Text("Save").padding(10)
|
|
|
+ })
|
|
|
+ .frame(width: UIScreen.main.bounds.width * 0.9, alignment: .center)
|
|
|
+ .background(Color(.systemBlue))
|
|
|
+ .tint(.white)
|
|
|
+ .clipShape(RoundedRectangle(cornerRadius: 8))
|
|
|
+ .padding(5)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -155,7 +222,7 @@ struct AddContactTrickSheet: View {
|
|
|
[Font.Weight.light, Font.Weight.regular, Font.Weight.medium, Font.Weight.bold, Font.Weight.black],
|
|
|
id: \.self
|
|
|
) { weight in
|
|
|
- Text("\(weight)".capitalized).tag(weight)
|
|
|
+ Text("\(weight.displayName)".capitalized).tag(weight)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -166,7 +233,7 @@ struct AddContactTrickSheet: View {
|
|
|
[Font.Width.standard, Font.Width.condensed, Font.Width.expanded],
|
|
|
id: \.self
|
|
|
) { width in
|
|
|
- Text("\(width)".capitalized).tag(width)
|
|
|
+ Text("\(width.displayName)".capitalized).tag(width)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -174,7 +241,7 @@ struct AddContactTrickSheet: View {
|
|
|
private func saveNewEntry() {
|
|
|
// Save the currently previewed entry
|
|
|
Task {
|
|
|
- await state.createAndSaveContactTrick(entry: previewEntry, name: name)
|
|
|
+ await state.createAndSaveContactTrick(entry: previewEntry, name: "Trio \(state.contactTrickEntries.count + 1)")
|
|
|
dismiss()
|
|
|
}
|
|
|
}
|