This commit is contained in:
Max Goedjen 2022-03-05 15:39:05 -08:00
parent 9fe1f0ca50
commit 28d0fc3adf
No known key found for this signature in database
GPG Key ID: E58C21DD77B9B8E8

View File

@ -8,7 +8,6 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
@State private var name = "" @State private var name = ""
@State private var requiresAuthentication = true @State private var requiresAuthentication = true
@State private var test: ThumbnailPickerView.Item = ThumbnailPickerView.Item(name: "Test", description: "Hello", thumbnail: Text("Hello"))
var body: some View { var body: some View {
VStack { VStack {
@ -26,22 +25,22 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
} }
if #available(macOS 12.0, *) { if #available(macOS 12.0, *) {
ThumbnailPickerView(items: [ 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(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(name: "Notify", ThumbnailPickerView.Item(value: false, name: "Notify",
description: "No authentication is required while your Mac is unlocked.", description: "No authentication is required while your Mac is unlocked.",
thumbnail: NotificationView()) thumbnail: NotificationView())
], selection: $test) ], selection: $requiresAuthentication)
} else { } else {
// HStack { HStack {
// VStack(spacing: 20) { VStack(spacing: 20) {
// Picker("", selection: $requiresAuthentication) { Picker("", selection: $requiresAuthentication) {
// Text("Requires Authentication (Biometrics or Password) before each use").tag(true) Text("Requires Authentication (Biometrics or Password) before each use").tag(true)
// Text("Authentication not required when Mac is unlocked").tag(false) Text("Authentication not required when Mac is unlocked").tag(false)
// } }
// .pickerStyle(SegmentedPickerStyle()) .pickerStyle(RadioGroupPickerStyle())
// } }
// Spacer() Spacer()
// } }
} }
} }
} }
@ -64,10 +63,16 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
} }
} }
struct ThumbnailPickerView<SelectionValue>: View where SelectionValue: Hashable { struct ThumbnailPickerView<ValueType: Hashable>: View {
private let items: [Item<ValueType>]
@Binding var selection: ValueType
init(items: [ThumbnailPickerView<ValueType>.Item<ValueType>], selection: Binding<ValueType>) {
self.items = items
_selection = selection
}
private let items: [Item]
@Binding private var selection: SelectionValue
var body: some View { var body: some View {
HStack { HStack {
@ -77,13 +82,13 @@ struct ThumbnailPickerView<SelectionValue>: View where SelectionValue: Hashable
.frame(width: 250, height: 200) .frame(width: 250, height: 200)
.clipShape(RoundedRectangle(cornerRadius: 10, style: .continuous)) .clipShape(RoundedRectangle(cornerRadius: 10, style: .continuous))
.overlay(RoundedRectangle(cornerRadius: 10) .overlay(RoundedRectangle(cornerRadius: 10)
.stroke(lineWidth: item == selection ? 5 : 0)) .stroke(lineWidth: item.value == selection ? 5 : 0))
.foregroundColor(.accentColor) .foregroundColor(.accentColor)
Text(item.name) Text(item.name)
.bold() .bold()
Text(item.description) Text(item.description)
}.onTapGesture { }.onTapGesture {
selection = item.thumbnail. selection = item.value
} }
} }
} }
@ -93,13 +98,15 @@ struct ThumbnailPickerView<SelectionValue>: View where SelectionValue: Hashable
extension ThumbnailPickerView { extension ThumbnailPickerView {
struct Item: Identifiable { struct Item<ValueType: Hashable>: Identifiable {
let id = UUID() let id = UUID()
let value: ValueType
let name: String let name: String
let description: String let description: String
let thumbnail: AnyView let thumbnail: AnyView
init<ViewType: View>(name: String, description: String, thumbnail: ViewType) { init<ViewType: View>(value: ValueType, name: String, description: String, thumbnail: ViewType) {
self.value = value
self.name = name self.name = name
self.description = description self.description = description
self.thumbnail = AnyView(thumbnail) self.thumbnail = AnyView(thumbnail)