I would like to create a Picker within my app’s settings which allows the user to select their notification tone. Specifically, I want the user to be able to preview this tone upon selecting it.
My current implementation actually achieves this. My picker has navigationLink style and contains several HStacks each consisting of Text and Button.
<pre class="s-code-block language-swift">
struct SettingsView: View {
...
var body: some View {
NavigationStack {
Form {
Toggle("Push Notifications", isOn: binding)
Picker("Tone", selection: $toneSelection) {
HStack {
Text("Simple")
Button(action: {playPreview(previewSound: "Sound1")}) {
Image(systemName: "speaker.wave.3.fill")
}
}.tag(NotificationType.simple)
HStack {
Text("Reverb")
Button(action: {playPreview(previewSound: "Sound2")}) {
Image(systemName: "speaker.wave.3.fill")
}
}.tag(NotificationType.reverb)
}
.pickerStyle(.navigationLink)
}
}
}
}
</pre>
But I’d like for the button/icon to disappear upon making the selection.
New contributor
Moe A is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.