I want to display a list of words in a flow layout manner and be able to "select" a word (tap on a word and know what word was tapped on). I was not able to figure out how to lay out individual words in a flowing manner, so I created a single Text
view with the words as a string separated by space, but now I don't know how to detect the word (or nil) tapped on with a onTapGesture
modifier. Is there a way?
@State var words : String = ["causticily", "sophora", "promiscuously", "lambaste", "pouring", "wagging", "tailblock", "coquette", "permeability", "rich", "enfilade", "centiloquy", "circumforaneous", "deturbation", "gecko", "nitro-chloroform", "migraine", "spellken", "convergence", "maggotish", "pester", "unprudent", "tenosynovitis", "yellowfish", "lionel", "turbinoid", "leased", "antitropous", "apportion", "metempsychosis", "ecchymosis", "beflower", "harns", "planetarium", "succinyl", "cremocarp", "catechisation", "capacify", "inburnt", "cabotage", "earing", "evestigate", "effectually", "balaniferous", "plowed", "angiospermatous", "acadian", "newfangly", "goblinize", "endotheca", "mesencephalon", "rose-colored", "talapoin", "academe", "cleanser", "escript", "vicine", "crossed"].joined(separator: " ")
var body : some View {
ZStack {
Text(self.words)
.lineLimit(nil)
.onTapGesture { // (word:String?) in
print("word=?")
}
}
}
Screenshot: