Moving between views in swift

  Kiến thức lập trình

I have a button in a separate component that I display in a menu. One of the buttons in the menu leads to the homepage where the menu is also displayed. When I start clicking the button, the same views will keep appearing continuously, causing the application view to start moving downward.

button view:


struct BtnMenu: View {
    
    @StateObject var logManager = MainViewModel()
    var btnText: String
    var btnIcon: String
    //var btnEvent: ()->Void
    var destinationView: AnyView
    
    var body: some View {
        Button{
                destinationView
        }label:{
            ZStack{
                Text("(Image(systemName: btnIcon)) (btnText)")
                    
            }
            
        }
    }
}

menu view:


struct BottomMenu: View {
    
    //zmienic zeby bylo przekazywane jako properties
    @StateObject var logManager = MainViewModel()
    var body: some View {
        HStack{
            Group{
                
            Spacer()
            BtnMenu(btnText: "Dodaj", btnIcon: "plus.app.fill",destinationView: AnyView(LoggedMainView()))
            Spacer()
            BtnMenu(btnText: "Szukaj", btnIcon: "magnifyingglass",destinationView: AnyView(SearchView()))
            Spacer()

            BtnMenu(btnText: "Profil", btnIcon: "person.crop.circle.fill",destinationView: AnyView(ProfileView()))
     
            Spacer()
          
        }.padding(.bottom, 30)
            .font(.system(size: 20))
        }
    }
}

I change NavigationLink from button to display new view, I tried to make state and state objects to compare the destination and current view but I can not get current view

LEAVE A COMMENT