Comments (7)
Hello @hcancelik . I've release v1.0.2 fixing accessibility of getCountries
.
For the 2nd part of your question. Can you please give details what do you mean by "way to get Country"?
from countrypicker.
Hi @Rashidium
Thanks for the update.
What I mean by getting the Country is basically an initializer in Country. Something like this:
public init(regionCode _regionCode: String) {
self.isoCode = _regionCode
if let country = CountryManager.shared.getCountries().first(where: { $0.isoCode == _regionCode }) {
self.phoneCode = country.phoneCode
} else {
self.phoneCode = ""
}
}
Since there is no way to get the phone code with iOS, this will help anyone to set a default value of the picker by using the Locale.current.region
from countrypicker.
@hcancelik have you checked the CountryPickerViewController.selectedCountry
? It can be used to set selected country by country code.
from countrypicker.
@hcancelik have you checked the
CountryPickerViewController.selectedCountry
? It can be used to set selected country by country code.
Yes I did. I might be doing something wrong but it doesn't provide a default value for the picker in swiftui. It only highlights the country in the list view.
from countrypicker.
can you please give any detail about highlighting? Do you mean selected background color under country code?
Also, could you please set selectedCountry
in func updateUIViewController(_ uiViewController: CountryPickerViewController, context: Context)
function?
from countrypicker.
@Rashidium What I meant was the set a default selected country for the picker.
Right now, I have set selectedCountry
to TR which sets a green background in the picker view but this is not enough to pre-select the value.
Simulator.Screen.Recording.-.iPhone.11.Pro.Max.-.2021-12-26.at.13.33.06.mp4
import SwiftUI
import CountryPicker
struct ContentView: View {
@State private var country: Country?
@State private var showCountryPicker = false
var body: some View {
VStack {
Button {
showCountryPicker = true
} label: {
Text("Select Country")
}.sheet(isPresented: $showCountryPicker) {
CountryPicker(country: $country)
}
Text("Selected Country: \(country?.localizedName ?? "N/A")")
}
}
}
Since with iOS, I can only get the Locale region, I thought it would be better to have a initializer in Country struct to set this default value.
public init(regionCode: String) {
self.isoCode = regionCode
if let country = CountryManager.shared.getCountries().first(where: { $0.isoCode == regionCode }) {
self.phoneCode = country.phoneCode
} else {
self.phoneCode = ""
}
}
This way I can set @State private var country = Country(regionCode: Locale.current.regionCode ?? "TR")
from countrypicker.
Ok I see what you meant now 👍🏻 Thanks for details. Though your solution would work, I think there could be better way to init Country without need to isoCode. I think we better open a pull request for the request you made.
from countrypicker.
Related Issues (11)
- Lisence HOT 1
- poping to the root HOT 1
- Index out of range when I select country from search result HOT 2
- Index out of range when I select country from search result HOT 9
- Hide Phone numbers HOT 1
- UIViewRepresentable
- Adding package failing HOT 1
- Feature Request: Multiple 'selectedCountry' HOT 1
- Example of UIViewControllerRepresentable HOT 3
- region-code only country initializer HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from countrypicker.