NavigationLink make a lot of blank spaces - swift

I'm currently working on a app ,and I encounter a weird problem , I use NavigationLink like this
NavigationLink(
destination: ContentView(),
label: {
Image(systemName: "house.fill")
})
This is the View before pressing home and back to the same view
I used this .navigationBarBackButtonHidden(true)and .navigationBarHidden(true) and
This is the View after a couple of back and forth
I'm curious if anyone encounter this problem and solve this .
It made a weird spacing on top
That didn't work , I delete the .navigationBarBackButtonHidden(true) so you can see what happen if I go to ContentView and back to the same View.
Going back and forth result in a lot of back buttons , ButtonHidden didn't help because just hide the button but the space is still there.
I want my application to have multiple functionality .
one view have a map , one an calendar and one note , for example . If I switch between View that happen , I got a lot of Back button . I want to know if is a solution for that navigationView to disappear and don't stack like that

Related

How to prevent spacing between content and back button in SwiftUI

The whole question is in the title. The 'United Kingdom' header should be at the top, but instead it is place away from the back button.
The worst part is, when I then go onto the 'Diamond-Encrusted Ring' page, it creates a new back button and even more spacing. I would prefer no spacing and to get rid of the 'Locations' back button once on the second page.
You use NavigationView only in the root View. So remove NavigationView from the views where this behavior is happening.

SwiftUI: Execute code when back button for NavigationView is pressed

I have MainView, which has a navigationLink to EditProfileView.
When I press the back button on EditProfileView, I want some code to execute that updates a database.
I would use onDisappear(), but the issue is that EditProfileView has another view ImagePickerView presented as a sheet come up, and having that view come up triggers onDisappear().
In other words, I want my database code to execute only when we press the back button to go from EditProfileView back to MainView.
Is there a way to do this?
Add your own back button to replace the native one as the left button. Then programmatically dismiss your view.

SwiftUI: disappearing popover on iPad only on some Views

I am experiencing problem with .popover() in SwiftUI it sometimes works correct, and other times it just appear and immediately disappear. Logging value of isPresented binding variable seems to show correct value.
Any idea why such thing can happen?
Moreover I have the same AddAttachment button that has popover() call added to different screen views and in one it works ok in other it stops working. Adding logs to init() of this screen views shows that value of isPresented #Binding var is ok (it is called several times (init()) but there is isPresented == true all the time after tapping button that should show popover). If popover disappear then taping button again changes #Binding var to false (so nothing show), and second consecutive tap make popover to appear and again immediately to disappear.

How do I navigate to another screen from a login screen with SwiftUI

I want to navigate from a splash/login view to a home view without the possibility of going back unless the user restarts the application using SwiftUI. I know I can use a navigation link and SwiftUI will present a back button. Is there a way to go from view to view without the back button?
If you need to present a view, you can look at this article
On the contrary if the concern is not to show the back button, on the home view one can hide the back button using the configuration like
.navigationBarBackButtonHidden(true)

Use NavigationLink programmatically in SwiftUI

I'm looking for a way to display a view in my WatchOS application "one level in" from the NavigationView on app startup if certain conditions are met.
I want the same effect as if I would have pressed a NavigationLink myself, i.e being able to go back to the NavigationView again, which is not possible if I choose to display the desired view right away.
"navigationBarItems" is also not available for WatchOS which makes it impossible to navigate backwards without actually clicking the NavigationLink in the first place.
Is there a way to programmatically "click" a NavigationLink in order to achieve this?
I don't have any experience with watchOS, but I've used the the "isActive" variant of NavigationLink for similar app needs.
In your initial view, define a #State var showOneLevelIn = false (or some other binding) and set that state var to true if you want the view to auto navigate to your second level. The label for the NavigationLink is an EmptyView() so it won't be visible in your initial view.
NavigationLink(destination: OneLevelInView(), isActive: $showOneLevelIn, label: { EmptyView() })