HomeiOS Developmentios - Unable to show a view with out making earlier one...

ios – Unable to show a view with out making earlier one shut in swiftui


Swift beginner right here. I am creating an app, i’ve a fundamental display, with a facet menu that may be opened from a hamburger icon and in the principle view there is a map, displaying my present location, additionally utilizing firebase for notifications.
I wish to present i view above the principle view at any time when an boolean ObservableObject haveOnGoingCall is modified, then on this new menus, if a button click on happens it ought to exit the brand new views and solely present one other
one containing couple buttons, which it ought to seem on the display when one other ObservableObject callPuttedOnHold is modified. I’ve few circumstances in the principle view to examine if the worth of the ObservableObject modified and present the views accordingly.

The primary view:

import SwiftUI

struct ContentViews: View {
    @State var presentSideMenu = false
    @State var showMenu = false
    @State var path = NavigationPath()
    
    @ObservedObject var newCall = ClientCallDefinitions()
            
    @State var refresher = 0
    
    var physique: some View {
        ZStack{
            MapContainerView()
                    .edgesIgnoringSafeArea(.all)
            
            VStack{
                MapView()
            }
            .body(maxWidth: .infinity, maxHeight: .infinity)
            .overlay(alignment: .prime){
                ZStack{
                    HStack{
                        Button(motion: {
                            withAnimation{
                                self.presentSideMenu.toggle()
                            }
                        }) {
                            Picture(systemName: "line.horizontal.3")
                                .imageScale(.massive)
                                .foregroundColor(.grey)
                                .padding(.main, 30)
                            
                            Spacer()
                        }
                        
                        Button(motion: {
                            
                        }) {
                            Picture(systemName: "paperplane")
                                .imageScale(.massive)
                                .foregroundColor(.grey)
                                .padding(.main, 30)
                                .body(width: 10, peak: 20)
                            
                            Spacer()
                        }
                        .padding(.main, 140)
                    }
                    .body(maxWidth: .infinity)
                    .body(peak: 56)
                    .background(Shade.white)
                    .zIndex(1)
                    .shadow(radius: 0.5)
                    
                }
                Textual content("Coonnecta shopper")
                    .multilineTextAlignment(.middle)
                
            }
            .body(maxWidth: .infinity)
            SideMenu()
                .zIndex(3)
            
          if newCall.haveOnGoingCall && !newCall.callPuttedOnHold {
                            clientCallViews()
                        } else if newCall.callPuttedOnHold {
                            CallPutOnHoldButtons()
                                .padding([.top], 600)
                                .zIndex(2)
                        }
                    }.refreshable {
                        refresher += 1
                    }
    }
    
    @ViewBuilder
    personal func clientCallPutOnHold() -> some View{
        CallPutOnHoldButtons()
    }
    
    @ViewBuilder
    personal func clientCallViews() -> some View{
        ClientCallInfoView()
            .body(width: 400)
            .background(.white)
            .padding([.bottom], 150)
            
        ClientCallEmergencyInfoView()
            .background(.white)
            .padding([.top], 310)
        
        ClientCallButtonsView()
            .padding([.top], 580)
    }
    
    @ViewBuilder
    personal func SideMenu() -> some View {
        Coonnecta_Client.SideMenu(isSideMenuShowing: $presentSideMenu, path: .main){
            SideMenuContents(presentSideMenu: $presentSideMenu)
                .body(width: 300)
        }
    }
    
    @ViewBuilder
    personal func MapView() -> some View {
        MapContainerView()
    }
}

struct ContentViews_Previews: PreviewProvider {
    static var previews: some View {
        ContentViews()
    }
}

The primary 3 views which are referred to as when the haveOnGoingCall boolean is modified:

import SwiftUI

struct ClientCallInfoView: View {
    var physique: some View {
        VStack(spacing: 20) {
            Textual content("Shopper")
                .body(maxWidth: .infinity, alignment: .main)
                .font(.system(measurement: 25, weight: .daring))
                .foregroundColor(.pink)

                    HStack {
                        VStack(alignment: .main, spacing: 3) {
                            Textual content("Shopper").font(.headline).daring()
                            Textual content("Ana Julia").font(.subheadline)
                        }
                        Spacer()
                        VStack(alignment: .main, spacing: 3) {
                            Textual content("System").font(.headline)
                            Textual content("DCs-DDS.FDGDF").font(.subheadline)
                        }
                    }

                    // Add a spacer to create area between rows

                    HStack {
                        VStack(alignment: .main, spacing: 3) {
                            Textual content("Group").font(.headline).daring()
                            Textual content("Lalala").font(.subheadline)
                        }
                        Spacer()
                        VStack(alignment: .main, spacing: 3) { // Set alignment to .trailing
                            Textual content("Plan Sort").font(.headline)
                            Textual content("Golden").font(.subheadline)
                        }
                        .padding(.main, -120) // Manually alter the place to the left
                    }
            
                    HStack {
                        VStack(alignment: .main, spacing: 3) {
                            Textual content("Blood sort").font(.headline).daring()
                            Textual content("-O").font(.subheadline)
                        }
                        Spacer()
                        VStack(alignment: .main, spacing: 3) { // Set alignment to .trailing
                            Textual content("Allergy").font(.headline)
                            Textual content("No").font(.subheadline)
                        }
                        .padding(.main, -120) // Manually alter the place to the left
                    }
            
                    HStack{
                        VStack(alignment: .main, spacing: 3) {
                            Textual content("Contacts").font(.headline).daring()
                            Textual content("2389548348").font(.subheadline)
                        }
                        Spacer()
                    }
                    
                }
                .padding()
            }
    
}
    
    
    struct ClientCallInfoView_Previews: PreviewProvider {
        static var previews: some View {
            ClientCallInfoView()
        }
    }


import SwiftUI

struct ClientCallEmergencyInfoView: View {
    var physique: some View {
        VStack(spacing: 20){
            Textual content("Emergency Information")
                .body(maxWidth: .infinity, alignment: .main)
                .font(.system(measurement: 25, weight: .daring))
                .foregroundColor(.pink)
            
            HStack {
                VStack(alignment: .main, spacing: 3) {
                    Textual content("Sort").font(.headline).daring()
                    Textual content("SOS-BLE").font(.subheadline)
                }
                Spacer()
                VStack(alignment: .main, spacing: 3) {
                    Textual content("Contacts").font(.headline)
                    Textual content("2389432390").font(.subheadline)
                }
            }
        }
        .padding()
    }
}

struct ClientCallEmergencyInfoView_Previews: PreviewProvider {
    static var previews: some View {
        ClientCallEmergencyInfoView()
    }
}

import SwiftUI

struct ClientCallButtonsView: View {
    @ObservedObject var callOnHold = ClientCallDefinitions()
    
    @Setting(.dismiss) var dismiss

    var physique: some View {
        VStack{
            HStack{
                Button (motion: {
                    ChangeCallDefinitionsState()
                    print(callOnHold.callPuttedOnHold)
                    print(callOnHold.haveOnGoingCall)
                    dismiss()

                }) {
                    Textual content("Placed on maintain")
                        .padding([.leading], 30)
                        .padding([.trailing], 30)

                }
                
                .padding()
                .background(.orange)
                .foregroundStyle(.white)
                .controlSize(.massive)
                
                Button (motion: {
                    
                }){
                    Textual content("Verify Alert")
                        .padding([.leading], 30)
                        .padding([.trailing], 30)
                }
                .padding()
                .background(.inexperienced)
                .foregroundStyle(.white)
            }
            
            Button(motion: {
                
            }){
                Textual content("Cancel")
                    .padding([.leading], 50)
                    .padding([.trailing], 50)
            }
            .padding()
            .background(.pink)
            .foregroundStyle(.white)
        }
        
        if callOnHold.callPuttedOnHold{
            clientCallPutOnHold()
        }
    }
    
    @ViewBuilder
    personal func clientCallPutOnHold() -> some View{
        CallPutOnHoldButtons()
    }

    func ChangeCallDefinitionsState(){
        DispatchQueue.foremost.async {
            callOnHold.callPuttedOnHold = true
            callOnHold.haveOnGoingCall = false
        }
    }
}

struct ClientCallButtonsView_Previews: PreviewProvider {
    static var previews: some View {
        ClientCallButtonsView()
    }
}

The observable object class the place i retailer the booleans:

import Basis

class ClientCallDefinitions: ObservableObject{
    @Printed var haveOnGoingCall: Bool = true
    @Printed var callPuttedOnHold: Bool = false
}

The difficulty is, at any time when i click on the button and it adjustments the ObservableObject worth, and the views are suppose to not seem, solely the brand new one CallPutOnHoldButtons ought to seem, the brand new one seems within the display, however the different ones doesn’t shut, altho the worth of the ObservableObject modified accurately.

Within the console i am getting a warning: “Publishing adjustments from inside view updates shouldn’t be allowed”.
Tried utilizing DispachQueue and Activity{…} however no outcomes.
Tried these couple options to make it go away however did not appear to work. Like utilizing the dismiss() perform, utilizing a situation in the principle view the place i present all of the views.

How am i able to repair this?
If extra info is required to grasp or replicate i can present.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments