SwiftUI - Setting NavBar items based on Sheet or NavigationLink presentation - ios

I have a view that is presented via sheet and navigation link. How can I tell if a view was shown via a Sheet or NavigationLink so that I can update my NavBar buttons appropriately? Right now, I'm using an "isModal" bool. It works, but is far from elegant. Building the navbar in the presenting view doesn't seem like a good solution. Is there a better way? Basically the same as this question except using SwiftUI How to check if a view controller is presented modally or pushed on a navigation stack?

Related

UINavigationController with UIHostingController correct way to navigate between screens

I have an existing app build with UIKit, Storyboards and existing UINavigationController. I want to add SwiftUI screens using UIHostingController, from this screen I want to navigate to another one. I embedded my Views in NavigationView and learned that now there are two navigation bar titles. I removed the NavigationView and just used navigationLink without it. I found out I can set navigation title on the hostingVC before I present it and with navigationTitle modifier, but they are changing the same thing.
How does this work and what should I use for navigation inside UIHostingController, should I build some custom UIKit solution for navigation?

My project has 2 navigation bar styes; default swiftui navbar and a custom one.Is there a way to hide the swiftUI navigation bar at a certain point?

I am doing a project where I am implementing the SwiftUI default navbar [navigation view and navigation link] and then I created my own custome navbar for the rest of the screens.
So, I am using the SwiftUI navbar for the login process in my application.
But after the user logs in, they are taken to the homepage. This is where I implemented my own navigationBar style.
Now you see, I linked the login button with the homepage using:
NavigationLink(destination: HomepageView())
You see where the problem is, it's like I'm nesting 2 navigation views and so I'm getting 2 navigation bars. I want to hide the default navigationBar that came from the login process.
So I tried using the [.navigationBarHidden(true)] but it does not work at all.
In short, how do I implement 2 navigation Views [one default, one custome] where I can use one for a section of my app and then the other for another section without having them to collide like this.
The best i could find was:
//added this to my HomepageView()
.navigationBarTitleDisplayMode(.inline)
.navigationBarHidden(true)
The navbar display mode changes to inline, but it is still there :)
I'm really a beginner still, so can you please help me.
Just have two UIViewControllers, one for the login and one for the home view.
So when it comes to redirecting from the login view to the home view. Do not redirect via NavigationLink because then you will end up with the same problem. (And it should not be possible if you do it properly, because your login and home views are held by their own UIViewControllers.)
Just close (viewControllerLogin.dismiss) the login view and (vieControllerHome.present) present the home screen.
If you google a bite you basically can wrap a (SwiftUI) View into a UIViewController should not be a problem. (it is quite common to do that.)
Something like that: Example

SwiftUI share same navigation bar after clicking navigation link

My app currently has a modal sheet that displays a view inside of a NavigationView. When I click on the NavigationLink I created, it takes me to the destination view in the same modal sheet, but I no longer have access to the navigation bar properties of the previous view (i.e. I can't set the navigation bar title or add navigation items).
I tried making another NavigationView in my second view, but this draws the navigation bar title 1/3 down the screen, and it also prevents me closing out of the entire modal sheet with my #Environment property-wrapped Binding variable. Does anyone have any ideas as to how I could fix this?
Not sure if this sounded clear at all, but I will be happy to clarify.

Swift Full Screen Navigation Push Segue

I want to achieve something similar to Facebook's way of presenting the comments view controller for a specific post. In below picture one can see, that the pushed new view controller is presented "full screen" (for the lack of a better way of describing the behaviour). It seems to me like some kind of modal segue rather than a push one. When trying to recreate that in my own app I can't achieve that the whole navigation bar is included in the presentation segue. Only the view inside the presentation hierarchy is changed. I want the second view controller to be entirely white (the view as well as the navigation bar) but both view controllers should have the default swipe-to-go-back behaviour. How can that be done?
What they're probably doing is hiding the navigation bar.
You can achieve the same effect if you set navigationController?.navigationBar.isHidden = true (can also do it on navigation bar in UINavigationController from the storyboard), make a regular show segue and just display it using performSegue(withIdentifier: "nextScreen", sender: nil). You can then make your own UI logic for displaying back buttons etc.

iOS: How to get a modal view to partially cover the parent view?

I am quite new in iOS development and I am facing an issue with the design of navigation. So my goal is simple: I have a view with a right navigation button which I want to open a modal view that would partially cover the parent view like on this screenshot: modal view example
Currently this is what I did: I embedded a UIViewController in a UINavigationController, then I added a right navigation button in my view controller which navigates to another UIViewController through a modal action segue. But whenever I navigate to the modal view, it fully covers the parent view.
So how can I get it to only cover partially the parent view with Interface Builder settings? Or do I need to use some code behind to achieve that?
Thanks for your help :)
NB: I don't want to use Popovers, I want it to be in the middle of the screen with no attach.
To achieve this you have to select your segue and modify the Presentation property to Form Sheet, as shown in the image below

Resources