Allow changing color

This commit is contained in:
Milan Stute
2021-03-10 17:02:52 +01:00
parent f7d9a17587
commit df917a7e64
2 changed files with 30 additions and 21 deletions

View File

@@ -20,6 +20,7 @@ struct AccessoryListEntry: View {
let formatter = DateFormatter()
@State var editingName: Bool = false
@State var editingColor: Bool = false
func timestampView() -> some View {
formatter.dateStyle = .short
@@ -39,6 +40,12 @@ struct AccessoryListEntry: View {
HStack {
IconSelectionView(selectedImageName: $accessoryIcon, selectedColor: $accessoryColor)
if self.editingColor {
ColorPicker(selection: $accessoryColor, supportsOpacity: false) {
EmptyView()
}
}
VStack(alignment: .leading) {
if self.editingName {
TextField("Enter accessory name", text: $accessoryName, onCommit: { self.editingName = false })
@@ -49,7 +56,6 @@ struct AccessoryListEntry: View {
.font(.headline)
}
self.timestampView()
}
Spacer()
@@ -65,11 +71,16 @@ struct AccessoryListEntry: View {
}
.padding(EdgeInsets(top: 5, leading: 0, bottom: 5, trailing: 0))
.contextMenu {
Button("Rename", action: { self.editingName = true })
Button("Delete", action: { self.delete(accessory) })
Divider()
Button("Rename", action: { self.editingName = true })
Button("Change color", action: { self.editingColor = true })
Divider()
Button("Copy advertisment key (Base64)", action: { self.copyPublicKey(of: accessory) })
Button("Copy key id (Base64)", action: { self.copyPublicKeyHash(of: accessory) })
Button("Copy key ID (Base64)", action: { self.copyPublicKeyHash(of: accessory) })
}
.onChange(of: self.accessoryColor) { _ in
self.editingColor = false
}
}

View File

@@ -68,26 +68,24 @@ struct ImageSelectionList: View {
let dismiss: () -> Void
var body: some View {
VStack {
List(self.selectableIcons, id: \.self) { iconName in
Button(
action: {
self.selectedImageName = iconName
self.dismiss()
},
label: {
HStack {
Spacer()
Image(systemName: iconName)
Spacer()
}
List(self.selectableIcons, id: \.self) { iconName in
Button(
action: {
self.selectedImageName = iconName
self.dismiss()
},
label: {
HStack {
Spacer()
Image(systemName: iconName)
Spacer()
}
)
.buttonStyle(PlainButtonStyle())
.contentShape(Rectangle())
}
.frame(width: 100)
}
)
.buttonStyle(PlainButtonStyle())
.contentShape(Rectangle())
}
.frame(width: 100)
}
}