I’ve the next SwiftUI view:
import SwiftUI
struct ContentView: View {
var gadgets = [1, 2]
var physique: some View {
NavigationStack {
Listing {
ForEach(self.gadgets, id: .self) { merchandise in
DisclosureGroup(content material: {
Textual content("Additional content material for merchandise (merchandise)")
}, label: {
HStack {
NavigationLink {
DetailView()
} label: {
Textual content("View Particulars")
}
.buttonStyle(.borderless)
}
})
}
}
}
}
}
Once I press wherever throughout the DisclosureGroup
, I would really like the “Additional content material” to indicate. Once I press particularly on the “View Particulars” button, I wish to navigate to the DetailView
.
Nonetheless, in the mean time, the NavigationLink
appears to be in some way overriding the ontap gesture of the DisclosureGroup
. If I click on wherever on the DisclosureGroup
, it navigates to DetailView
– solely displaying the “Additional content material” if I explicitly click on on the DisclosureGroup
‘s arrow.
I attempted lots of the solutions in this query:
Whereas altering Listing
to ScrollView
does work, it additionally messes up the padding, and I’m not certain if there’s a clear approach to apply it to the ScrollView
(if Apple modifications the Listing
styling sooner or later, I need my View to replace mechanically with out altering the code).
Altering the buttonStyle
to .borderless
does not cease the NavigationLink
from overriding the ontap gesture.
I can’t use a hidden NavigationLink
with chosen
or isActive
, as a result of these are deprecated in iOS 16.
In the meantime, embedding the NavigationLink
inside a button does not navigate to the DetailView
– it simply performs the button’s motion as a substitute.