Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI navigationView within Modal 'pushing' view down

I currently have a modal view in SwiftUI that contains a series of NavigationLinks to different views. However, when I go to one of the other views it pushes all the content down leaving a empty forehead at the top of the view. How do I fix this? I have included an example screenshot below.

enter image description here

To further clarify, there is a main view with a button that opens a Modal view. This modal contains a navigation view with a series of NavigationLink Buttons. When opening the navigation links within the modal, that is when the view is pushed down.

like image 211
Thomas Braun Avatar asked Feb 18 '26 07:02

Thomas Braun


2 Answers

You have a large navigation bar, try to set navigationBar displayMode to .inline

.navigationBarTitle(Text(""), displayMode: .inline)
like image 106
Sorin Lica Avatar answered Feb 19 '26 22:02

Sorin Lica


This probably happens because the view you push to from the NavigationView is also wrapped in a NavigationView.

struct SettingsView: View {
    var body: some View {
        NavigationView {
           NavigationLink(destination: IAPView()) {
               Text("In App Purchase")
           }
       }
    }
}

You probably have this in the IAPView()

struct IAPView: View {
        var body: some View {
            NavigationView { <-- this is causing it
               // your buttons here
           }
        }
    }
like image 25
Jordi Bruin Avatar answered Feb 19 '26 22:02

Jordi Bruin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!