Saturday, January 13, 2024
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 primary display screen, with a aspect menu that may be opened from a hamburger icon and in the primary view there is a map, exhibiting my present location, additionally utilizing firebase for notifications.
I wish to present i view above the primary view each time 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 screen when one other ObservableObject callPuttedOnHold is modified. I’ve few situations in the primary view to test if the worth of the ObservableObject modified and present the views accordingly.

The principle 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: .high){
                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, top: 20)
                            
                            Spacer()
                        }
                        .padding(.main, 140)
                    }
                    .body(maxWidth: .infinity)
                    .body(top: 56)
                    .background(Coloration.white)
                    .zIndex(1)
                    .shadow(radius: 0.5)
                    
                }
                Textual content("Coonnecta shopper")
                    .multilineTextAlignment(.heart)
                
            }
            .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
    non-public func clientCallPutOnHold() -> some View{
        CallPutOnHoldButtons()
    }
    
    @ViewBuilder
    non-public func clientCallViews() -> some View{
        ClientCallInfoView()
            .body(width: 400)
            .background(.white)
            .padding([.bottom], 150)
            
        ClientCallEmergencyInfoView()
            .background(.white)
            .padding([.top], 310)
        
        ClientCallButtonsView()
            .padding([.top], 580)
    }
    
    @ViewBuilder
    non-public func SideMenu() -> some View {
        Coonnecta_Client.SideMenu(isSideMenuShowing: $presentSideMenu, route: .main){
            SideMenuContents(presentSideMenu: $presentSideMenu)
                .body(width: 300)
        }
    }
    
    @ViewBuilder
    non-public 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(dimension: 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("Gadget").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 Kind").font(.headline)
                            Textual content("Golden").font(.subheadline)
                        }
                        .padding(.main, -120) // Manually modify 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 modify 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(dimension: 25, weight: .daring))
                .foregroundColor(.pink)
            
            HStack {
                VStack(alignment: .main, spacing: 3) {
                    Textual content("Kind").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
    non-public func clientCallPutOnHold() -> some View{
        CallPutOnHoldButtons()
    }

    func ChangeCallDefinitionsState(){
        DispatchQueue.predominant.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, each time 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 screen, 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 isn’t 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() operate, utilizing a situation in the primary 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.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments