I have a series of views in SwiftUI. One is a "Menu View" which consists of a List of NavigationLinks wrapped in a NavigationView.
The code is as follows.
var body: some View {
NavigationView {
List {
HStack {
NavigationLink(destination: History(), isActive: $isHistoryViewActive) {
Image(systemName: "clock")
Text("History")
}
}
HStack {
NavigationLink(destination: Settings(), isActive: $isSettingsActive) {
Image(systemName: "gear")
Text("Settings")
}
}
HStack {
Image(systemName: "info.circle.fill")
Button(action: {
...
}) {
Text("My Button")
}
}
}
}
}
The Settings view is as follows
var body: some View {
List {
...
Section(header: "Background Music") {
Toggle("Play", isOn: $isBackGroundMusicOn)
}
Section(header: "Voice Setting") {
HStack {
NavigationLink(destination: VoiceList() {
Text(self.voiceNames[self.selectedVoice])
}
}
}
}
And lastly, the VoiceList view is as follows:
var body: some View {
List {
ForEach(0 ..< VoiceList.voiceNames.count) {voiceIndex in
HStack {
Button(action: {
voiceChanged(selectedVoice: voiceIndex)
}){
Text(VoiceList.voiceNames[voiceIndex])
}
Spacer()
Image(systemName: "checkmark")
.frame(alignment: .trailing)
.foregroundColor(.blue)
.isHidden(hidden: voiceIndex != selectedVoice)
}
}
}
}
The problem that I am having is that when the app returns from the VoiceList view to the Settings view, the NavigationLink remains highlighted, as if it is still active, as shown in the attached screenshot. I honestly have no idea what may be causing this. Any ideas or insights are greatly appreciated.