Created
March 7, 2021 15:29
-
-
Save prafullakumar/a4d4d62cade2400e0df1dac9ceb95f53 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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