My app has a List/Detail View hierarchy. I want to make the object's name in the detail view a clickable link when a URL is provided. This is what I'm trying to do:
var body: some View {
if object.url != "" {
Link(object.name, destination: URL(string: object.url)!)
} else {
Text(object.name)
.font(.title2)
}
...some other view code...
Unfortunately, in my detail view, this isn't working. The link appears as blue text as you would expect, but clicking it does not open the browser. I've tried substituting var strings for both of these to confirm it wasn't a missing data issue, and the correct URL prints to console when the view loads, so I know the view has it. This code works in views farther up the hierarchy, so I theorize this is something I'm doing when switching from the List to the Detail view.
My list code looks like this:
ForEach(app.objects) { object in
NavigationLink {
ObjectDetailView(object: object, app: app)
} label: {
ObjectRow(object: object)
}
}
... some other view code...
This is the second NavigationLink in my view hierarchy, if that matters. Something between this view and the Detail view is causing the URL to not be clickable. I'm wondering if there's something obvious I don't know like the fact that this is the second NavigationLink in my hierarchy that is causing issues. Any insight would be appreciated!
Update:
I never did figure out this issue. In a subsequent refactor, I have switched to using tab views inside the Detail view and now it works. I did have similar issues with a different element not being clickable when it appeared at the top of the Detail view, so my current working theory is that something in a parent view is somehow "obscuring" a portion of the Detail view and rendering elements in it unable to register a tap gesture. The other element I had issues with - a simple toggle - when I moved it physically lower in the view, it worked. I think this might be related to my implementation of .searchable - details in this other post.