Add code for a popover for adding new destinations.

This commit is contained in:
Jeremy Rand 2021-11-02 23:04:02 -04:00
parent 3b2d4beb55
commit c9936e82f5
2 changed files with 26 additions and 3 deletions

View File

@ -18,6 +18,8 @@ struct DestinationsView: View {
Destination(ipAddress: "192.168.1.21")
]
@State private var editMode = EditMode.inactive
@State private var showPopover = false
@State private var newDestination = ""
var body: some View {
List {
@ -37,12 +39,27 @@ struct DestinationsView: View {
private var addButton: some View {
switch editMode {
case .inactive:
return AnyView(Button(action: onAdd) { Image(systemName: "plus") })
return AnyView(Button(action: showAdd) { Image(systemName: "plus") }
.popover(
isPresented: self.$showPopover,
arrowEdge: .bottom
) { addPopover } )
default:
return AnyView(EmptyView())
}
}
private var addPopover: some View {
VStack {
Text("Enter the hostname or\nIP address of your GS:")
TextField("New destination", text: self.$newDestination) { isEditing in
} onCommit: {
onAdd()
}
}
.padding()
}
private func onDelete(offsets: IndexSet) {
destinations.remove(atOffsets: offsets)
}
@ -51,8 +68,14 @@ struct DestinationsView: View {
destinations.move(fromOffsets: source, toOffset: destination)
}
func showAdd() {
self.showPopover = true;
}
func onAdd() {
destinations.append(Destination(ipAddress: "192.168.1.22"))
destinations.append(Destination(ipAddress: self.newDestination))
newDestination = ""
showPopover = false;
}
}

View File

@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>188</string>
<string>210</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSRequiresIPhoneOS</key>