I tried to explain the issues I was having with the current SwiftUI navigation options yesterday, but I donāt think I did a good job š So hereās a second stab at it ā¦
Basically, my understanding is that the only out-of-the-box way to show new views is to either use a NavigationLink or a sheet. I had a List where I wanted the user clicking on the list cell to take them to one view and the user clicking on a button within the list view to take them to another view. (See screenshot #1). This was fairly easy to do in UIKit.
But when I use NavigationLinks for both items, they automatically add these disclosure indicators and doubles them for two NavigationLinks (yes, I know you can hide them with some jugglery, but you shouldnāt need to do that). Worse still, you still get taken to only one view no matter where you click š
Fine, so two NavigationLinks in the same cell wonāt work. So letās try making one of them (the button) show a sheet instead. That should work, right?
And this does indeed work. (See screenshot #2).
So all is well? Well kinda ā¦ First, I shouldnāt need to show a sheet when I donāt want to. If I want to push a new view in, then I should be able to do so, right?
But leaving that quibble aside, letās say I want my cell to have a distinctive look. Like in screenshot #3. But now I have the disclosure indicator outside my content cell. And that really doesnāt look good to me ā¦
Oh, but you can put the NavigationLink and the cell content in a ZStack to control that, you say? Sure, but then things look like screenshot #4 š Sure, with some more tweaking I can probably get things working right but shouldnāt this be easier?
Also, do note that you can set the opacity of the NavigationLink to 0 and hide the disclosure indicator altogether and yet have the NavigationLink work. And thatās what I did in my app, but in that app, setting things up this way wouldnāt work for the two separate views. Tapping on the button would launch both the detail view and the other view.
But it works correctly here. So I think I must have gotten something subtle wrong in the other implementation.
However, if you want to avoid all these hassles, you might want to try out this package:
https://github.com/DoubleSymmetry/XNavigationIt let me do view navigation the way I wanted to, instead of having to use sheets when I didnāt want to use sheets š
If you have a better way to do what I was trying to do, please do let me know. Iām always eager to learn š
Disclaimer: I am not affiliated to the developer of the package in any way. I just liked how it made navigation so much easier ā¦ at least for the use cases I had.
#iOS #SwiftUI #Coding #Navigation #AppleScreenshot #1. Trying to use twā¦Screenshot #2. The button/imageā¦Screenshot #3. Adding a backgroā¦Screenshot #4. The disclosure iā¦