Skip to content

Instantly share code, notes, and snippets.

@jbadger3
Last active November 19, 2020 19:10
Show Gist options
  • Save jbadger3/dd16779537f2b1bb8721298837a7ebf0 to your computer and use it in GitHub Desktop.
Save jbadger3/dd16779537f2b1bb8721298837a7ebf0 to your computer and use it in GitHub Desktop.
NavigableListWithInteractiveCells
Button(action: {
currentFavorite = teamMember
}, label: {
Image(systemName: (teamMember == currentFavorite ? "heart.fill" : "heart"))
.foregroundColor(.pink)
})
.buttonStyle(PlainButtonStyle())
struct NavigableListWithButton: View {
private let xmen = ["Wolverine","Cyclops", "Storm", "Rogue", "Iceman", "Beast", "Professor X"]
@State var currentFavorite = ""
var body: some View {
NavigationView {
List {
ForEach(xmen, id:\.self) { teamMember in
NavigationLink(destination: Text(teamMember)) {
HStack {
Button(action: {currentFavorite = teamMember}, label: {
Image(systemName: (teamMember == currentFavorite ? "heart.fill" : "heart"))
.foregroundColor(.pink)
})
Text(teamMember)
}
}
}
}
.navigationBarTitle("The X-Men", displayMode: .automatic)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment