Skip to content

Instantly share code, notes, and snippets.

@prafullakumar
Created March 7, 2021 15:29
Show Gist options
  • Save prafullakumar/a4d4d62cade2400e0df1dac9ceb95f53 to your computer and use it in GitHub Desktop.
Save prafullakumar/a4d4d62cade2400e0df1dac9ceb95f53 to your computer and use it in GitHub Desktop.
struct SearchBarDemo: View {
@State private var searchText = ""
@State private var isEditing = false
let countryList = Locale.isoRegionCodes.compactMap { Locale.current.localizedString(forRegionCode: $0) }
var body: some View {
NavigationView {
List {
Section.init(header:
SearchBar(text: $searchText, isEditing: $isEditing),
content: {
ForEach(countryList.filter( { searchText.isEmpty ? true : $0.contains(searchText) } ), id: \.self) { country in
Text(country)
}
})
}
.navigationTitle("Demo")
.navigationBarHidden(isEditing).animation(.linear(duration: 0.25))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment