Post

Replies

Boosts

Views

Activity

Mystery Inverted Bool
Can someone help me figure out why the "stillLoading" boolean seems to be the opposite of what it should be? The first print outputs false, and the second outputs true, and this is opposite of what it should be. I also tried using the boolean the other way around as "doneLoading," but when I flipped the values, the outputs were still opposite of what they should have been. Here is a copy-pastable Working Example. I'm pretty new to SwiftUI, so I may be misunderstanding something fundamental. Anyway, any help is greatly appreciated! import Foundation import UIKit class AddParticipantModel: ObservableObject { @Published var firstName: String = "" @Published var lastName: String = "" @Published var dateOfBirth: Date = Date() @Published var address1: String = "" @Published var address2: String = "" @Published var city: String = "" @Published var state: String = "NV" @Published var zip: String = "" @Published var showErrorAlert: Bool = false @Published var stillLoading: Bool = false func addParticipant(authString: String) async { let participant: Participant = Participant(id: "", approved: ApprovalStatus.Pending, active: false, firstName: firstName, lastName: lastName, dob: dateOfBirth, programStart: Date(), address1: address1, address2: address2, city: city, state: state, zip: zip) DispatchQueue.main.async { self.stillLoading = true } /***********************Printing false*******************************/ print(stillLoading) await AddParticipantAction( parameters: AddParticipantRequest( participant: participant, deviceId: UIDevice.current.identifierForVendor!.uuidString, authString: authString ) ).call { response in //Check for an error response from the API if response.errorNumber == 0{ DispatchQueue.main.async{ self.showErrorAlert = false; self.stillLoading = false; } } else if response.errorNumber == 5 || response.errorNumber == 10{ DispatchQueue.main.async{ self.showErrorAlert = false; self.stillLoading = false; } Auth.shared.logout() } else{ DispatchQueue.main.async{ self.showErrorAlert = true; self.stillLoading = false; } } /***********************Printing true*******************************/ print(self.stillLoading) } } }
2
0
457
Aug ’23
SwiftUI Overlay within NavigationView z-index layering issues
I'm pretty new to Swift, so if there is a better way to do what I'm trying to do, please let me know. On the main view, I have a list that navigates to other views, and I have a sidebar that overlays the main view when the user presses the menu button. I want to add navigation links in the sidebar, so I extended the NavigationView to encompass the sidebar view. Now the issue I'm running into is that the Navigation Title and toolbar remain on top of the sidebar when it comes into view. struct ParticipantListScreen: View { @ObservedObject var participantListViewModel: ParticipantListViewModel = ParticipantListViewModel() @ObservedObject var portalUserViewModel: PortalUserViewModel = PortalUserViewModel() @AppStorage("lastUpdated") var lastUpdated = Date.distantFuture.timeIntervalSince1970 @State var isSidebarOpened = false @State private var filterParticipantListBy: ApprovalStatus = ApprovalStatus.All @State var isLoading = false var filteredParticipants: [Participant] { participantListViewModel.participants.filter{ participant in (filterParticipantListBy == ApprovalStatus.All || participant.approved == filterParticipantListBy) } } var body: some View { NavigationView{ ZStack{ VStack{ //NavigationView{ ZStack{ VStack{ List{ Picker("Show only", selection: $filterParticipantListBy) { Text("Show All").tag(ApprovalStatus.All) Text("Approved").tag(ApprovalStatus.Approved) Text("Denied").tag(ApprovalStatus.Denied) Text("Pending").tag(ApprovalStatus.Pending) } ForEach(filteredParticipants) { participant in NavigationLink{ ParticipantDetail(participant:participant) }label:{ ParticipantRow(participant:participant) } } } .navigationTitle("Participants") .toolbar(content: toolbarContent) .refreshable { participantListViewModel.getParticipants(authString: Auth.shared.getAccessToken()!) } //ProgressView().opacity(1) } //} Spacer() }.zIndex(1) } ZStack{ Sidebar( isSidebarVisible: $isSidebarOpened, participantListViewModel: participantListViewModel, portalUserViewModel: portalUserViewModel ).zIndex(110) }.zIndex(100) }.zIndex(50) } .onAppear(perform: { participantListViewModel.getParticipants(authString: Auth.shared.getAccessToken()!) portalUserViewModel.getUser(authString: Auth.shared.getAccessToken()!) }) } } Any help would be greatly appreciated! P.S. I'm really enjoying learning SwiftUI, so any other tips on the above code would be awesome. Thanks in advance! Explain what you did and what you expected: I tried extending the navigation view to include my sidebar view. I expected to eventually have a sidebar with working navigationLinks. The nav links do work fine, but toolbar components and the navigation title now appear on top of the side bar. I didn't expect it to be perfect right off the bat, but after hours of fiddling and searching, I'm no closer to getting the sidebar to properly overlay all the other ui components. Minimum Working Example
3
0
2.1k
Aug ’23