diff --git a/o-fish-ios.xcodeproj/project.pbxproj b/o-fish-ios.xcodeproj/project.pbxproj index a4d1352b..58fd700c 100644 --- a/o-fish-ios.xcodeproj/project.pbxproj +++ b/o-fish-ios.xcodeproj/project.pbxproj @@ -193,7 +193,6 @@ BCE4814543022D42A642CA4A /* KeyboardController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCE486CABA40FF0D6D14E5F9 /* KeyboardController.swift */; }; BCE4815F88C024AD476B8DE2 /* DutyState.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCE48D936613848423BBAF33 /* DutyState.swift */; }; BCE4817B0B89F5D95768925A /* CountryPickerView.swif.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCE486BCBC428C8539A22A9D /* CountryPickerView.swif.swift */; }; - BCE481FC2E1771F65073C0A6 /* ReportSummaryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCE483CAE164B70D857A62B0 /* ReportSummaryView.swift */; }; BCE4820A7E5A15B8AA93DB4A /* TextPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCE48555D654177BE1259C7B /* TextPickerView.swift */; }; BCE4825F4A971D6F6F24D571 /* CatchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCE48E5B87FCD1126A5C26C4 /* CatchView.swift */; }; BCE48275C134A902EF0293D4 /* GlassIconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCE48B8D8932DF568200B811 /* GlassIconView.swift */; }; @@ -249,7 +248,6 @@ BCE48B02D6D3331545500562 /* ChooseSpeciesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCE48FAB856639D53CABC76C /* ChooseSpeciesView.swift */; }; BCE48B088018D82ECFC5F7A9 /* MultiRowPickerWithButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCE4817C8B123F01E50A23D9 /* MultiRowPickerWithButton.swift */; }; BCE48B09547E88D2E76107BB /* Collection+EnumeratedArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCE48EFBBE1997660C4F1EE6 /* Collection+EnumeratedArray.swift */; }; - BCE48B31FB9BEA734058DAA9 /* ReportListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCE48A5038A2E43FE839DC80 /* ReportListView.swift */; }; BCE48B41FAB47CB8B9B0AE61 /* SearchBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCE48D44A5E464AA9AC620E8 /* SearchBarView.swift */; }; BCE48B59A51E4AF79D2FAEE1 /* TextLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCE4871B39646A85F047F256 /* TextLabel.swift */; }; BCE48B9CAD5B8F1EB27C60BD /* ChooseEMSView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCE48E42E19241E2A8EC419F /* ChooseEMSView.swift */; }; @@ -491,7 +489,6 @@ BCE482F2C7BF11E33FA5E862 /* StartStopDatePicker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StartStopDatePicker.swift; sourceTree = ""; }; BCE483315BCBE777464D2FF4 /* ViolationPickerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViolationPickerView.swift; sourceTree = ""; }; BCE483BB45A7BCD0ADC62551 /* PopoverManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PopoverManager.swift; sourceTree = ""; }; - BCE483CAE164B70D857A62B0 /* ReportSummaryView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReportSummaryView.swift; sourceTree = ""; }; BCE48456167E25D77C838694 /* CrewMemberShortView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CrewMemberShortView.swift; sourceTree = ""; }; BCE484CE2776AE6F4E5A5791 /* ChooseBusinessView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChooseBusinessView.swift; sourceTree = ""; }; BCE484E6974BBB4F08413A3E /* InputField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InputField.swift; sourceTree = ""; }; @@ -531,7 +528,6 @@ BCE489F610C0078AE3ED2944 /* TopTabBarContainerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TopTabBarContainerView.swift; sourceTree = ""; }; BCE489F75FEB031E1F2AAC20 /* ScrollableTabBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollableTabBar.swift; sourceTree = ""; }; BCE489FD715E47C868F5D581 /* PatrolSummaryView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PatrolSummaryView.swift; sourceTree = ""; }; - BCE48A5038A2E43FE839DC80 /* ReportListView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReportListView.swift; sourceTree = ""; }; BCE48AB036DA398FBFF3E3B4 /* SectionButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SectionButton.swift; sourceTree = ""; }; BCE48AB83BB50A193A6B4113 /* CallToActionButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CallToActionButton.swift; sourceTree = ""; }; BCE48AF913D1F963F18F6FAF /* KeyboardControllingScrollView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyboardControllingScrollView.swift; sourceTree = ""; }; @@ -807,7 +803,6 @@ 493CDFB923FEB86D00516048 /* LoginView.swift */, 3013CA782424AF1300D2FF60 /* PatrolBoat */, BCE483F917662257CAB7586F /* ReportFlow */, - BCE48B378C5953371739F735 /* ReportList */, ); path = Views; sourceTree = ""; @@ -1196,15 +1191,6 @@ path = Country; sourceTree = ""; }; - BCE48B378C5953371739F735 /* ReportList */ = { - isa = PBXGroup; - children = ( - BCE48A5038A2E43FE839DC80 /* ReportListView.swift */, - BCE483CAE164B70D857A62B0 /* ReportSummaryView.swift */, - ); - path = ReportList; - sourceTree = ""; - }; BCE48B73700857DD26654AED /* Popover */ = { isa = PBXGroup; children = ( @@ -1711,9 +1697,7 @@ 3013CA802424B07300D2FF60 /* TextToggle.swift in Sources */, BCE48BFCEE413835DEB14DC0 /* RowView.swift in Sources */, BCE48B59A51E4AF79D2FAEE1 /* TextLabel.swift in Sources */, - BCE48B31FB9BEA734058DAA9 /* ReportListView.swift in Sources */, 49B83EDB2489546D00027B8C /* SafetyLevel.swift in Sources */, - BCE481FC2E1771F65073C0A6 /* ReportSummaryView.swift in Sources */, BCE4856F6CE56291D9BCB13E /* VesselView.swift in Sources */, BCE483F97684587434E8421E /* ReportNavigationRootView.swift in Sources */, BCE482FC535CCA17C9D9F30A /* EMSInputView.swift in Sources */, diff --git a/o-fish-ios/Views/Components/BoardVesselButton.swift b/o-fish-ios/Views/Components/BoardVesselButton.swift index 172b05eb..93f22034 100644 --- a/o-fish-ios/Views/Components/BoardVesselButton.swift +++ b/o-fish-ios/Views/Components/BoardVesselButton.swift @@ -12,6 +12,7 @@ struct BoardVesselButton: View { @ObservedObject var onDuty: DutyState var report = ReportViewModel() var onHeader = true + @Binding var rootIsActive: Bool @State private var showingReportRootView = false @State private var showingGoOnDutyAlert = false @@ -49,7 +50,8 @@ struct BoardVesselButton: View { } NavigationLink(destination: ReportNavigationRootView(report: prefilledReport, - prefilledVesselAvailable: true), + prefilledVesselAvailable: true, + rootIsActive: $rootIsActive), isActive: $showingReportRootView) { EmptyView() } @@ -69,6 +71,7 @@ struct BoardVesselButton: View { struct BoardVesselButton_Previews: PreviewProvider { static var previews: some View { - BoardVesselButton(onDuty: .sample) + BoardVesselButton(onDuty: .sample, + rootIsActive: .constant(true)) } } diff --git a/o-fish-ios/Views/PatrolBoat/PatrolBoatView.swift b/o-fish-ios/Views/PatrolBoat/PatrolBoatView.swift index 226878fd..fe7d0760 100644 --- a/o-fish-ios/Views/PatrolBoat/PatrolBoatView.swift +++ b/o-fish-ios/Views/PatrolBoat/PatrolBoatView.swift @@ -14,9 +14,9 @@ struct PatrolBoatView: View { var isLoggedIn: Binding @State private var location = LocationViewModel(LocationHelper.currentLocation) - @State private var showingPreboardingView = false - @State private var showingSearchView = false - @State private var showingPatrolSummaryView = false + @State private var isActiveRootFromPreboardingView = false + @State private var isActiveRootFromSearchView = false + @State private var isActiveRootFromShowingPatrolSummaryView = false @State private var resetLocation = {} @State private var dutyReports = [ReportViewModel]() @@ -41,10 +41,18 @@ struct PatrolBoatView: View { var body: some View { VStack { SearchBarButton(title: "Find records", action: { - self.showingSearchView.toggle() + self.isActiveRootFromSearchView.toggle() }) .padding(.vertical, Dimensions.topPadding) + NavigationLink(destination: PreboardingView(viewType: .searchRecords, + onDuty: onDuty, + rootIsActive: $isActiveRootFromSearchView), + isActive: $isActiveRootFromSearchView) { + EmptyView() + } + .isDetailLink(false) + ZStack(alignment: .bottom) { MapComponentView(location: self.$location, reset: self.$resetLocation, @@ -62,7 +70,7 @@ struct PatrolBoatView: View { Spacer() BoardButtonView { if self.onDuty.onDuty { - self.showingPreboardingView.toggle() + self.isActiveRootFromPreboardingView.toggle() } else { self.showGoOnDutyAlert() } @@ -71,27 +79,25 @@ struct PatrolBoatView: View { .padding(.horizontal, Dimensions.allCoordPadding) NavigationLink( - destination: PreboardingView(viewType: .preboarding, onDuty: onDuty), - isActive: self.$showingPreboardingView) { - EmptyView() + destination: PreboardingView(viewType: .preboarding, + onDuty: onDuty, + rootIsActive: $isActiveRootFromPreboardingView), + isActive: self.$isActiveRootFromPreboardingView) { + EmptyView() } - } - - NavigationLink(destination: PreboardingView(viewType: .searchRecords, - onDuty: onDuty), - isActive: self.$showingSearchView) { - EmptyView() + .isDetailLink(false) } NavigationLink(destination: PatrolSummaryView(dutyReports: dutyReports, startDuty: startDuty, onDuty: onDuty, - plannedOffDutyTime: plannedOffDutyTime), - - isActive: self.$showingPatrolSummaryView) { + plannedOffDutyTime: plannedOffDutyTime, + rootIsActive: $isActiveRootFromShowingPatrolSummaryView), + isActive: $isActiveRootFromShowingPatrolSummaryView) { EmptyView() } + .isDetailLink(false) } .edgesIgnoringSafeArea(.all) .navigationBarItems( @@ -247,7 +253,7 @@ struct PatrolBoatView: View { self.startDuty = startDuty self.plannedOffDutyTime = endDutyTime dutyReports = dutyReportsForCurrentUser(startDutyTime: startDuty.date, endDutyTime: endDutyTime) - showingPatrolSummaryView = true + isActiveRootFromShowingPatrolSummaryView = true } /// Logic diff --git a/o-fish-ios/Views/PatrolBoat/PatrolSummary/PatrolSummaryView.swift b/o-fish-ios/Views/PatrolBoat/PatrolSummary/PatrolSummaryView.swift index bfc846a2..9c8dd0de 100644 --- a/o-fish-ios/Views/PatrolBoat/PatrolSummary/PatrolSummaryView.swift +++ b/o-fish-ios/Views/PatrolBoat/PatrolSummary/PatrolSummaryView.swift @@ -14,6 +14,7 @@ struct PatrolSummaryView: View { @ObservedObject var startDuty: DutyChangeViewModel @ObservedObject var onDuty: DutyState @State var plannedOffDutyTime: Date + @Binding var rootIsActive: Bool @State private var showingBoardingRecordView = false @State private var selectedReport = ReportViewModel() @@ -68,7 +69,10 @@ struct PatrolSummaryView: View { .compositingGroup() .bottomShadow() - NavigationLink(destination: BoardingRecordView(report: selectedReport, onDuty: onDuty), isActive: $showingBoardingRecordView) { + NavigationLink(destination: BoardingRecordView(report: selectedReport, + onDuty: onDuty, + rootIsActive: $rootIsActive), + isActive: $showingBoardingRecordView) { EmptyView() } } @@ -103,6 +107,7 @@ struct PatrolSummaryView_Previews: PreviewProvider { PatrolSummaryView(dutyReports: [.sample, .sample, .sample], startDuty: .sample, onDuty: .sample, - plannedOffDutyTime: Date()) + plannedOffDutyTime: Date(), + rootIsActive: .constant(true)) } } diff --git a/o-fish-ios/Views/PreboardingFlow/PreboardingView/PreboardingLoadedStateView.swift b/o-fish-ios/Views/PreboardingFlow/PreboardingView/PreboardingLoadedStateView.swift index 2daca9e2..1e48f945 100644 --- a/o-fish-ios/Views/PreboardingFlow/PreboardingView/PreboardingLoadedStateView.swift +++ b/o-fish-ios/Views/PreboardingFlow/PreboardingView/PreboardingLoadedStateView.swift @@ -11,6 +11,7 @@ struct PreboardingLoadedStateView: View { @ObservedObject var onDuty: DutyState @Binding var storedReports: [ReportViewModel] @Binding var showingRecentBoardings: Bool + @Binding var rootIsActive: Bool @State private var showingReport: ReportViewModel = .sample @State private var showingLoadingVesselRecordsView = false @@ -44,7 +45,7 @@ struct PreboardingLoadedStateView: View { } } - NavigationLink(destination: LoadingVesselRecordView(report: showingReport, onDuty: self.onDuty), + NavigationLink(destination: LoadingVesselRecordView(report: showingReport, onDuty: self.onDuty, rootIsActive: $rootIsActive), isActive: $showingLoadingVesselRecordsView) { EmptyView() } @@ -64,6 +65,7 @@ struct PreboardingLoadedStateView_Previews: PreviewProvider { PreboardingLoadedStateView( onDuty: DutyState.shared, storedReports: .constant([.sample, .sample]), - showingRecentBoardings: .constant(true)) + showingRecentBoardings: .constant(true), + rootIsActive: .constant(true)) } } diff --git a/o-fish-ios/Views/PreboardingFlow/PreboardingView/PreboardingView.swift b/o-fish-ios/Views/PreboardingFlow/PreboardingView/PreboardingView.swift index 65e4c16f..63001b04 100644 --- a/o-fish-ios/Views/PreboardingFlow/PreboardingView/PreboardingView.swift +++ b/o-fish-ios/Views/PreboardingFlow/PreboardingView/PreboardingView.swift @@ -19,6 +19,7 @@ struct PreboardingView: View { var viewType: ViewType = .preboarding @ObservedObject var onDuty: DutyState + @Binding var rootIsActive: Bool @State private var searchText = "" @State private var showingDismissAlert = false @@ -45,7 +46,7 @@ struct PreboardingView: View { searchBar if showingAddVessel { - NavigationLink(destination: ReportNavigationRootView()) { + NavigationLink(destination: ReportNavigationRootView(rootIsActive: $rootIsActive)) { VStack(spacing: Dimension.noSpacing) { IconLabel(imagePath: "plus", title: "Add New Vessel") .padding(.vertical, Dimension.padding) @@ -106,7 +107,8 @@ struct PreboardingView: View { return AnyView(PreboardingLoadedStateView( onDuty: onDuty, storedReports: $storedReports, - showingRecentBoardings: $showingRecentBoardings) + showingRecentBoardings: $showingRecentBoardings, + rootIsActive: $rootIsActive) ) case .loading: @@ -196,10 +198,12 @@ struct PreboardingView_Previews: PreviewProvider { static var previews: some View { VStack { PreboardingView(viewType: .preboarding, - onDuty: .sample) + onDuty: .sample, + rootIsActive: .constant(true)) Divider() PreboardingView(viewType: .searchRecords, - onDuty: .sample) + onDuty: .sample, + rootIsActive: .constant(true)) } } } diff --git a/o-fish-ios/Views/PreboardingFlow/VesselRecordView/LoadingVesselRecordView.swift b/o-fish-ios/Views/PreboardingFlow/VesselRecordView/LoadingVesselRecordView.swift index b8f6f535..4e773d00 100644 --- a/o-fish-ios/Views/PreboardingFlow/VesselRecordView/LoadingVesselRecordView.swift +++ b/o-fish-ios/Views/PreboardingFlow/VesselRecordView/LoadingVesselRecordView.swift @@ -13,6 +13,7 @@ struct LoadingVesselRecordView: View { @Environment(\.presentationMode) var presentationMode @ObservedObject var report: ReportViewModel @ObservedObject var onDuty: DutyState + @Binding var rootIsActive: Bool @State private var storedReports: [ReportViewModel] = [] @State private var loading = true @@ -23,7 +24,7 @@ struct LoadingVesselRecordView: View { if loading { LoadingIndicatorView(isAnimating: self.$loading, style: .large) } else { - VesselRecordView(reports: storedReports, onDuty: onDuty) + VesselRecordView(reports: storedReports, onDuty: onDuty, rootIsActive: $rootIsActive) } } .navigationBarTitle("Vessel", displayMode: .inline) @@ -52,6 +53,7 @@ struct LoadingVesselRecordView: View { struct LoadingVesselRecordView_Previews: PreviewProvider { static var previews: some View { LoadingVesselRecordView(report: .sample, - onDuty: .sample) + onDuty: .sample, + rootIsActive: .constant(true)) } } diff --git a/o-fish-ios/Views/PreboardingFlow/VesselRecordView/VesselRecordHeaderView.swift b/o-fish-ios/Views/PreboardingFlow/VesselRecordView/VesselRecordHeaderView.swift index b3e889cc..d42a8f5c 100644 --- a/o-fish-ios/Views/PreboardingFlow/VesselRecordView/VesselRecordHeaderView.swift +++ b/o-fish-ios/Views/PreboardingFlow/VesselRecordView/VesselRecordHeaderView.swift @@ -14,6 +14,7 @@ struct VesselRecordHeaderView: View { var boardings: Int var warnings: Int var citations: Int + @Binding var rootIsActive: Bool @State private var vesselImages: [AnyView] = [] @@ -51,7 +52,7 @@ struct VesselRecordHeaderView: View { } .padding(.horizontal, Dimensions.padding) - BoardVesselButton(onDuty: onDuty, report: report) + BoardVesselButton(onDuty: onDuty, report: report, rootIsActive: $rootIsActive) } .onAppear(perform: onAppear) } @@ -108,6 +109,7 @@ struct VesselRecordHeaderView_Previews: PreviewProvider { onDuty: .sample, boardings: 5, warnings: 0, - citations: 2) + citations: 2, + rootIsActive: .constant(true)) } } diff --git a/o-fish-ios/Views/PreboardingFlow/VesselRecordView/VesselRecordView.swift b/o-fish-ios/Views/PreboardingFlow/VesselRecordView/VesselRecordView.swift index a89315eb..e3a8ce38 100644 --- a/o-fish-ios/Views/PreboardingFlow/VesselRecordView/VesselRecordView.swift +++ b/o-fish-ios/Views/PreboardingFlow/VesselRecordView/VesselRecordView.swift @@ -11,6 +11,7 @@ struct VesselRecordView: View { @State var reports: [ReportViewModel] @ObservedObject var onDuty: DutyState + @Binding var rootIsActive: Bool @State private var showingBoardingRecordView = false @State private var selectedReport = ReportViewModel() @State private var stillLoading = true @@ -55,7 +56,8 @@ struct VesselRecordView: View { onDuty: onDuty, boardings: numberOfBoardings, warnings: numberOfWarnings, - citations: numberOfCitations) + citations: numberOfCitations, + rootIsActive: $rootIsActive) .background(Color.white) .compositingGroup() .defaultShadow() @@ -83,7 +85,10 @@ struct VesselRecordView: View { } //TODO Need to replace to ForEach. For now it's unexpected behavior with showing mapViewImage. - NavigationLink(destination: BoardingRecordView(report: selectedReport, onDuty: onDuty), isActive: $showingBoardingRecordView) { + NavigationLink(destination: BoardingRecordView(report: selectedReport, + onDuty: onDuty, + rootIsActive: $rootIsActive), + isActive: $showingBoardingRecordView) { EmptyView() } } @@ -102,7 +107,8 @@ struct VesselRecordView_Previews: PreviewProvider { static var previews: some View { NavigationView { VesselRecordView(reports: [.sample, .sample, .sample], - onDuty: .sample) + onDuty: .sample, + rootIsActive: .constant(true)) } } } diff --git a/o-fish-ios/Views/ReportDetails/BoardingRecordView.swift b/o-fish-ios/Views/ReportDetails/BoardingRecordView.swift index dec2a058..63b683ab 100644 --- a/o-fish-ios/Views/ReportDetails/BoardingRecordView.swift +++ b/o-fish-ios/Views/ReportDetails/BoardingRecordView.swift @@ -10,6 +10,7 @@ import SwiftUI struct BoardingRecordView: View { @ObservedObject var report: ReportViewModel @ObservedObject var onDuty: DutyState + @Binding var rootIsActive: Bool @Environment(\.presentationMode) var presentationMode: Binding @@ -73,7 +74,7 @@ struct BoardingRecordView: View { } } - BoardVesselButton(onDuty: onDuty, report: report, onHeader: false) + BoardVesselButton(onDuty: onDuty, report: report, onHeader: false, rootIsActive: $rootIsActive) .edgesIgnoringSafeArea(.bottom) .background(Color.white) .compositingGroup() @@ -92,7 +93,9 @@ struct BoardingRecordView: View { struct BoardingRecordView_Previews: PreviewProvider { static var previews: some View { NavigationView { - BoardingRecordView(report: .sample, onDuty: .sample) + BoardingRecordView(report: .sample, + onDuty: .sample, + rootIsActive: .constant(true)) .environmentObject(Settings.shared) } } diff --git a/o-fish-ios/Views/ReportFlow/ReportNavigationRootView.swift b/o-fish-ios/Views/ReportFlow/ReportNavigationRootView.swift index e4f4b1c5..7de0b0cd 100644 --- a/o-fish-ios/Views/ReportFlow/ReportNavigationRootView.swift +++ b/o-fish-ios/Views/ReportFlow/ReportNavigationRootView.swift @@ -11,14 +11,16 @@ struct ReportNavigationRootView: View { @Environment(\.presentationMode) var presentationMode @ObservedObject var report: ReportViewModel + @Binding var rootIsActive: Bool private var prefilledVesselAvailable: Bool @State private var showingAlertItem: AlertItem? @State private var notFilledScreens: [String] = TopTabBarItems.allCases.map { $0.rawValue } - init(report: ReportViewModel? = nil, prefilledVesselAvailable: Bool = false) { + init(report: ReportViewModel? = nil, prefilledVesselAvailable: Bool = false, rootIsActive: Binding) { self.report = report ?? ReportViewModel() self.prefilledVesselAvailable = prefilledVesselAvailable + _rootIsActive = rootIsActive if let menuData = RealmConnection.realm?.objects(MenuData.self).first { Settings.shared.menuData = menuData } else { @@ -87,19 +89,20 @@ struct ReportNavigationRootView: View { private func discardReport() { report.discard() - presentationMode.wrappedValue.dismiss() + rootIsActive.toggle() } private func saveAlertClicked() { print("Saving report in Realm") report.save() - presentationMode.wrappedValue.dismiss() + rootIsActive.toggle() } } struct ReportNavigationRootView_Previews: PreviewProvider { static var previews: some View { - ReportNavigationRootView(report: ReportViewModel.sample) + ReportNavigationRootView(report: ReportViewModel.sample, + rootIsActive: .constant(true)) .environmentObject(Settings.shared) } } diff --git a/o-fish-ios/Views/ReportList/ReportListView.swift b/o-fish-ios/Views/ReportList/ReportListView.swift deleted file mode 100644 index d15a6488..00000000 --- a/o-fish-ios/Views/ReportList/ReportListView.swift +++ /dev/null @@ -1,106 +0,0 @@ -// -// ReportListView.swift -// -// Created on 25/02/2020. -// Copyright © 2020 WildAid. All rights reserved. -// - -import SwiftUI -import RealmSwift - -class RefreshHack: ObservableObject { - // TODO remove when Realm refreshes the view automatically - @Published fileprivate var refreshToken = 0 -} - -struct ReportListView: View { - @Environment(\.presentationMode) var presentationMode - - // TODO remove when Realm refreshes the view automatically - @ObservedObject private var refreshHack = RefreshHack() - - @State private var storedReports: Results? - @State private var creatingNewReport = true - @State private var reportToEdit: ReportViewModel? - @State private var pushedEditReportFlow = false - @State private var errorMessage = "" - @State private var loading = false - - private let horizontalPadding: CGFloat = 10.0 - - var body: some View { - GeometryReader { geo in - ScrollView { - VStack { - Text(self.errorMessage) - .foregroundColor(.red) - - // Ideally would use `if let` here, but that isn't supported within a view and so - // we check that it's not `nil` and then unwrap it - if self.storedReports != nil { - ForEach(self.storedReports!) { report in - VStack { - Button(action: { self.reportItemClicked(item: ReportViewModel(report)) }) { - ReportSummaryView(report: ReportViewModel(report)) - } - Divider() - } - .padding([.horizontal, .top], self.horizontalPadding) - } - } else { - Text("Cannot access reports") - } - NavigationLink(destination: ReportNavigationRootView(report: self.reportToEdit), - isActive: self.$pushedEditReportFlow) { - EmptyView() - } - } - .frame(width: geo.size.width) - } - } - .navigationBarItems( - leading: Button(action: refresh) { - HStack { - Image(systemName: "arrow.down.doc") - Text("Refresh") - } - }, - trailing: Button(action: newReportClicked) { - HStack { - Text("Add Report") - Image(systemName: "plus") - } - } - ) - .navigationBarTitle("Contact Reports", displayMode: .inline) - .onAppear(perform: loadReports) - } - - private func refresh() { - refreshHack.refreshToken += 1 - } - - private func loadReports() { - storedReports = RealmConnection.realm?.objects(Report.self).sorted(byKeyPath: "timestamp", ascending: false) - } - - private func reportItemClicked(item: ReportViewModel) { - creatingNewReport = false - reportToEdit = item - pushedEditReportFlow = true - } - - private func newReportClicked() { - creatingNewReport = true - reportToEdit = nil - pushedEditReportFlow = true - } -} - -struct ReportListView_Previews: PreviewProvider { - static var previews: some View { - NavigationView { - ReportListView() - } - } -} diff --git a/o-fish-ios/Views/ReportList/ReportSummaryView.swift b/o-fish-ios/Views/ReportList/ReportSummaryView.swift deleted file mode 100644 index 8b6ae055..00000000 --- a/o-fish-ios/Views/ReportList/ReportSummaryView.swift +++ /dev/null @@ -1,31 +0,0 @@ -// -// ReportSummaryView.swift -// -// Created on 25/02/2020. -// Copyright © 2020 WildAid. All rights reserved. -// - -import SwiftUI - -struct ReportSummaryView: View { - var report: ReportViewModel - - var body: some View { - VStack(alignment: .leading, spacing: 0) { - CaptionLabel(title: report.id) - - HStack(alignment: .center, spacing: 8) { - Text("Vessel: " + report.vessel.name) - Text("Date: " + Date.getPrintStringFromDate(report.date)) - } - .font(.caption) - .foregroundColor(.gray) - } - } -} - -struct ReportSummaryView_Previews: PreviewProvider { - static var previews: some View { - ReportSummaryView(report: .sample) - } -}