From 28d0fc3adfb08d6582c4466d277cadbba254e201 Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Sat, 5 Mar 2022 15:39:05 -0800 Subject: [PATCH] T/F --- .../Secretive/Views/CreateSecretView.swift | 49 +++++++++++-------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/Sources/Secretive/Views/CreateSecretView.swift b/Sources/Secretive/Views/CreateSecretView.swift index a1c0b7d..a52679a 100644 --- a/Sources/Secretive/Views/CreateSecretView.swift +++ b/Sources/Secretive/Views/CreateSecretView.swift @@ -8,7 +8,6 @@ struct CreateSecretView: View { @State private var name = "" @State private var requiresAuthentication = true - @State private var test: ThumbnailPickerView.Item = ThumbnailPickerView.Item(name: "Test", description: "Hello", thumbnail: Text("Hello")) var body: some View { VStack { @@ -26,22 +25,22 @@ struct CreateSecretView: View { } if #available(macOS 12.0, *) { ThumbnailPickerView(items: [ - ThumbnailPickerView.Item(name: "Require Authentication", description: "You will be required to authenticate using Touch ID, Apple Watch, or password before each use.", thumbnail: AuthenticationView()), - ThumbnailPickerView.Item(name: "Notify", + ThumbnailPickerView.Item(value: true, name: "Require Authentication", description: "You will be required to authenticate using Touch ID, Apple Watch, or password before each use.", thumbnail: AuthenticationView()), + ThumbnailPickerView.Item(value: false, name: "Notify", description: "No authentication is required while your Mac is unlocked.", thumbnail: NotificationView()) - ], selection: $test) + ], selection: $requiresAuthentication) } else { - // HStack { - // VStack(spacing: 20) { - // Picker("", selection: $requiresAuthentication) { - // Text("Requires Authentication (Biometrics or Password) before each use").tag(true) - // Text("Authentication not required when Mac is unlocked").tag(false) - // } - // .pickerStyle(SegmentedPickerStyle()) - // } - // Spacer() - // } + HStack { + VStack(spacing: 20) { + Picker("", selection: $requiresAuthentication) { + Text("Requires Authentication (Biometrics or Password) before each use").tag(true) + Text("Authentication not required when Mac is unlocked").tag(false) + } + .pickerStyle(RadioGroupPickerStyle()) + } + Spacer() + } } } } @@ -64,10 +63,16 @@ struct CreateSecretView: View { } } -struct ThumbnailPickerView: View where SelectionValue: Hashable { +struct ThumbnailPickerView: View { + + private let items: [Item] + @Binding var selection: ValueType + + init(items: [ThumbnailPickerView.Item], selection: Binding) { + self.items = items + _selection = selection + } - private let items: [Item] - @Binding private var selection: SelectionValue var body: some View { HStack { @@ -77,13 +82,13 @@ struct ThumbnailPickerView: View where SelectionValue: Hashable .frame(width: 250, height: 200) .clipShape(RoundedRectangle(cornerRadius: 10, style: .continuous)) .overlay(RoundedRectangle(cornerRadius: 10) - .stroke(lineWidth: item == selection ? 5 : 0)) + .stroke(lineWidth: item.value == selection ? 5 : 0)) .foregroundColor(.accentColor) Text(item.name) .bold() Text(item.description) }.onTapGesture { - selection = item.thumbnail. + selection = item.value } } } @@ -93,13 +98,15 @@ struct ThumbnailPickerView: View where SelectionValue: Hashable extension ThumbnailPickerView { - struct Item: Identifiable { + struct Item: Identifiable { let id = UUID() + let value: ValueType let name: String let description: String let thumbnail: AnyView - init(name: String, description: String, thumbnail: ViewType) { + init(value: ValueType, name: String, description: String, thumbnail: ViewType) { + self.value = value self.name = name self.description = description self.thumbnail = AnyView(thumbnail)