mirror of
https://github.com/jeremysrand/ListenerApp.git
synced 2024-06-01 07:41:59 +00:00
Add code for a popover for adding new destinations.
This commit is contained in:
parent
3b2d4beb55
commit
c9936e82f5
|
@ -18,6 +18,8 @@ struct DestinationsView: View {
|
||||||
Destination(ipAddress: "192.168.1.21")
|
Destination(ipAddress: "192.168.1.21")
|
||||||
]
|
]
|
||||||
@State private var editMode = EditMode.inactive
|
@State private var editMode = EditMode.inactive
|
||||||
|
@State private var showPopover = false
|
||||||
|
@State private var newDestination = ""
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
List {
|
List {
|
||||||
|
@ -37,12 +39,27 @@ struct DestinationsView: View {
|
||||||
private var addButton: some View {
|
private var addButton: some View {
|
||||||
switch editMode {
|
switch editMode {
|
||||||
case .inactive:
|
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:
|
default:
|
||||||
return AnyView(EmptyView())
|
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) {
|
private func onDelete(offsets: IndexSet) {
|
||||||
destinations.remove(atOffsets: offsets)
|
destinations.remove(atOffsets: offsets)
|
||||||
}
|
}
|
||||||
|
@ -51,8 +68,14 @@ struct DestinationsView: View {
|
||||||
destinations.move(fromOffsets: source, toOffset: destination)
|
destinations.move(fromOffsets: source, toOffset: destination)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func showAdd() {
|
||||||
|
self.showPopover = true;
|
||||||
|
}
|
||||||
|
|
||||||
func onAdd() {
|
func onAdd() {
|
||||||
destinations.append(Destination(ipAddress: "192.168.1.22"))
|
destinations.append(Destination(ipAddress: self.newDestination))
|
||||||
|
newDestination = ""
|
||||||
|
showPopover = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>1.0</string>
|
<string>1.0</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>188</string>
|
<string>210</string>
|
||||||
<key>LSApplicationCategoryType</key>
|
<key>LSApplicationCategoryType</key>
|
||||||
<string>public.app-category.utilities</string>
|
<string>public.app-category.utilities</string>
|
||||||
<key>LSRequiresIPhoneOS</key>
|
<key>LSRequiresIPhoneOS</key>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user