Giter Site home page Giter Site logo

countrypicker's People

Contributors

10macit avatar alantonica avatar emoonadev avatar hmgezer avatar huseyinmobven avatar karazeynep avatar naymanfatih avatar pjay avatar rashidium avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

countrypicker's Issues

Lisence

Hello mates, could you please to update the license to use your library?
I love your library. It may help me save the time.
Thank you very much <3

Example of UIViewControllerRepresentable

Here is an example of UIViewControllerRepresentable that works with SwiftUI.

Please feel free to add this to docs.

//
//  CountryPicker.swift
//

import SwiftUI
import CountryPicker

struct CountryPicker: UIViewControllerRepresentable {
    @Binding var country: Country?
    
    typealias UIViewControllerType = CountryPickerViewController
    
    let countryPicker = CountryPickerViewController()
    
    func makeUIViewController(context: Context) -> CountryPickerViewController {
        countryPicker.selectedCountry = Locale.current.regionCode ?? "US"
        countryPicker.delegate = context.coordinator
        
        return countryPicker
    }
    
    func updateUIViewController(_ uiViewController: CountryPickerViewController, context: Context) {
        //
    }
    
    func makeCoordinator() -> Coordinator {
        return Coordinator(self)
    }
    
    class Coordinator: NSObject, CountryPickerDelegate {
        var parent: CountryPicker
        
        init(_ parent: CountryPicker) {
            self.parent = parent
        }
        
        func countryPicker(didSelect country: Country) {
            parent.country = country
        }
    }
}

Example Usage:

//
//  ContentView.swift
//

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)
            }
        }
    }
}

Hide Phone numbers

I don't see for now a way to hide the phone numbers from the list view.
Can you also add that please?

There are cases when i only need the flag and the country, but showing the phone number is not necessary.

region-code only country initializer

@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")

Originally posted by @hcancelik in #6 (comment)

Feature Request: Multiple 'selectedCountry'

Reuquest for a feature where a specified list of countries was on the top of list.

fx

let countryPicker = CountryPickerViewController()
countryPicker.preferedCountries = ["DK", "SE", "NO"]

UIViewRepresentable

struct CountryPicker : UIViewControllerRepresentable{

typealias UIViewControllerType = CountryPickerViewController

let countryPicker = CountryPickerViewController()
func makeUIViewController(context: Context) -> CountryPickerViewController {

countryPicker.selectedCountry = "TR"
return countryPicker

}

func updateUIViewController(_ uiViewController: CountryPickerViewController, context: Context) {

}
func makeCoordinator() -> Coordinator {
return Coordinator(countryPicker)
}

class Coordinator : NSObject , CountryPickerDelegate{

init(_ parent : CountryPickerViewController) {
    super.init()
    parent.delegate = self
}

func countryPicker(didSelect country: Country) {
    print(country)
}

}
}

poping to the root

When using this plugin on my swiftui app on the last page, when the country list open, the navigationview pop to the root view. any ideas. thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.