Created
September 24, 2021 18:56
-
-
Save dmytro-anokhin/b95a5b247971ee5dca546e82d608ac3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ContentView: View { | |
@ObservedObject private var autocomplete = AutocompleteObject() | |
@State var input: String = "" | |
var body: some View { | |
VStack { | |
TextField("", text: $input) | |
.textFieldStyle(.roundedBorder) | |
.padding() | |
.onChange(of: input) { newValue in | |
autocomplete.autocomplete(input) | |
} | |
} | |
List(autocomplete.suggestions, id: \.self) { suggestion in | |
ZStack { | |
Text(suggestion) | |
} | |
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading) | |
.onTapGesture { | |
input = suggestion | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment