From c9936e82f515a597ec414e7f60b8c1d85bfe07e4 Mon Sep 17 00:00:00 2001 From: Jeremy Rand Date: Tue, 2 Nov 2021 23:04:02 -0400 Subject: [PATCH] Add code for a popover for adding new destinations. --- DestinationsView.swift | 27 +++++++++++++++++++++++++-- ListenerGS/Info.plist | 2 +- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/DestinationsView.swift b/DestinationsView.swift index 15548a2..2c96021 100644 --- a/DestinationsView.swift +++ b/DestinationsView.swift @@ -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; } } diff --git a/ListenerGS/Info.plist b/ListenerGS/Info.plist index 310597b..0d7120c 100644 --- a/ListenerGS/Info.plist +++ b/ListenerGS/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString 1.0 CFBundleVersion - 188 + 210 LSApplicationCategoryType public.app-category.utilities LSRequiresIPhoneOS