I know SwiftUI doesn't come with a TokenList built in (maybe some day?) So I'm trying to simulate one.
The situation: I've got a book with multiple authors (say, like an anthology.)
I've created a "quasi-token" view and put it in a horizontal list:
private func personToken(_ person: NamedPerson) -> some View {
Text(person.description)
.font(.headline)
.padding(8.0)
.foregroundColor(.white)
.background(Color.blue)
.cornerRadius(25.0)
}
private var authorTokenList: some View {
HStack {
ForEach(book.authors) { author in
personToken(author)
}
}
}
Which looks pretty good at first glance:
My first problem (reserving the possibility to expand as further issues become apparent) is that the tokens themselves wrap if the HStack
gets too wide for the view:
It would be better if the HStack
resized vertically to accomodate more tokens, but while I can find tutorials on making a scrollable horizontal view, I'm not sure how to make a vertically-resizable HStack
.
I'm also going to want to add context-menu like functionality to each token on a long press gesture (maybe?) to delete or re-order the tokens, but I need to try to work that out before I have any specific questions about it.