0

I have the following code:

First Struct:

struct MenuButton: View {

    var buttonText: String
    var buttonCallView: AnyView

    var body: some View {
        NavigationView{
            NavigationLink(destination: self.buttonCallView) {
                Text(self.buttonText)
            }
        }
    }
}

Second Struct:

struct ProfileMenuContent: View {
    var body: some View {
        VStack{
            MenuButton(buttonText: "Settings", buttonCallView: AnyView(SettingsView()))
            MenuButton(buttonText: "My Favourites", buttonCallView: AnyView(MyFavouritesView()))
            MenuButton(buttonText: "Sign Out", buttonCallView: AnyView(SignOutView()))
        }
    }
}

This produces the following behaviour: if

What I want: When one button gets pressed, rather then just taking the 1/3th of the space for the new View it should take the fullscreen.

1 Answer 1

1

To get your wanted behavior, all you have to do is remove the NavigationView from inside the MenuBotton struct and add a NavigationView to your ProfileMenuContent.

new code:

struct MenuButton: View {

    var buttonText: String
    var buttonCallView: AnyView

    var body: some View {
        NavigationLink(destination: self.buttonCallView) {
            Text(self.buttonText)
        }
    }
}

struct ProfileMenuContent: View {
    var body: some View {
        NavigationView {
            VStack {
                MenuButton(buttonText: "Settings", buttonCallView: AnyView(SettingsView()))
                MenuButton(buttonText: "My Favourites", buttonCallView: AnyView(MyFavouritesView()))
                MenuButton(buttonText: "Sign Out", buttonCallView: AnyView(SignOutView()))
            }
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.