GithubHelp home page GithubHelp logo

suryakantsharma / countrypicker Goto Github PK

View Code? Open in Web Editor NEW
281.0 8.0 86.0 124.73 MB

A simple, customizable Country picker for picking country or dialing code. ๐Ÿ‡ฎ๐Ÿ‡ณ ๐Ÿ‡ฏ๐Ÿ‡ต ๐Ÿ‡ฐ๐Ÿ‡ท ๐Ÿ‡ฉ๐Ÿ‡ช ๐Ÿ‡จ๐Ÿ‡ณ ๐Ÿ‡บ๐Ÿ‡ธ ๐Ÿ‡ซ๐Ÿ‡ท ๐Ÿ‡ช๐Ÿ‡ธ ๐Ÿ‡ฎ๐Ÿ‡น ๐Ÿ‡ท๐Ÿ‡บ ๐Ÿ‡ฌ๐Ÿ‡ง

License: MIT License

Swift 92.66% Ruby 6.71% Objective-C 0.51% C 0.12%
ios country-picker cocoapods xcode country-flags countrylist countrycodes country-selection swift filter-countries

countrypicker's Introduction

CountryPicker

CountryPicker

Awesome Build Status

codecov Version Badge

Carthage compatible Swift Package Manager compatible License

CountryPicker is a Swift library that provides a simple and easy-to-use interface for selecting countries from a predefined list. It's perfect for adding country selection functionality to your iOS app with minimal effort.

If you like CountryPicker, give it a โ˜… at the top right of this page.

Features

  • Navigate through search and index title of section e.g (in Contact app in iOS)
  • Auto scroll to previous selected country
  • Filtering country options
  • Styling view options
  • Image size are optimized
  • Cocoa Pods integrated
  • Carthage integrated
  • Swift package manager integrated
  • Best practices followed
  • Dark mode supported
  • Support Dynamic font size for ContentSizeCategory
  • Unit tests coverage 94%
  • Picker view support added with customization
  • Swift UI Support with example project
  • Rewritten with swiftUI and combine in version 3.0.0

Requirements

  • iOS 15.0+ Support latest release iOS 17 for older user older than 3.0.0
  • latest Xcode 15.x with Swift

Demo Project

To run the example project, clone the repo, and run pod update from the Example directory first.

Swift UI Combine new project

|

Screenshots

Home Scene Country Picker Scene Filtering Scene Dark Mode Scene Picker View

Installation

CountryPicker is available through Cocoapods and Carthage.

Add the following line to your Podfile:

For iOS 15 and above (Combine and Swiftui version) currently only supported by cocoapods 
pod 'SKCountryPicker'

Please note iOS 15 will be discontinued after in 2024.

The steps required to use Carthage for dependency management are described here but lets add them to this README as well for good measure.

First you need to add the following line to your Cartfile

github "SURYAKANTSHARMA/CountryPicker"

to include the latest version of CountryPicker.

(if you don't have a Cartfile, you need to create one first in your favorite texteditor)

Next run

carthage update --platform iOS

This will have Carthage:

  • Fetch the source code for CountryPicker from Github
  • Compile the source code into a framework for you to use

once Carthage finishes building, you need to add the framework to your project.

In Xcode:

  • Navigate to the "General" tab of your project and tap the plus sign under "Frameworks, Libraries and Embedded Content"
  • Select "Add other" and locate the Carthage folder (typically in the root of your project)
  • The SKCountryPicker.framework is located under Carthage/Build/iOS/
  • Select it and verify that it is added as a framework.

The final step is to add the copy-frameworks build script to your "Build Phases".

  • Navigate to "Build Phases" and tap the + at the top.
  • Select "New Run Script Phase"
  • Paste this line as the script to run /usr/local/bin/carthage copy-frameworks
  • Add the SKCountryPicker.framework under Input Files like so: $(SRCROOT)/Carthage/Build/iOS/SKCountryPicker.framework

Done!

Add the following line to your Package.swift file in the dependencies section:

.package(url: "https://github.com/SURYAKANTSHARMA/CountryPicker.git, from "4.0.0")

Getting Started

Please check baseiOS11Example project for customization and different option available for using with old uikit.

Please check baseiOS15Example project for using it in swift ui app with minimum deployment target iOS 15

Filter Options

There are 3 main filter options countryName, countryCode, countryDialCode and by default country picker has been configured to filter countries based on countryName.

If you want to add/remove filter options, do as follows:

 // Adding filter
 CountryManager.shared.addFilter(.countryCode)

 // Removing filter
 CountryManager.shared.removeFilter(.countryCode)

 // Removing all filters
 CountryManager.shared.clearAllFilters()

Incase you want to retrieve country info

// Get country based on digit code e.g: 60, +255
CountryManager.shared.country(withDigitCode: "255")

// Get country based on country name
CountryManager.shared.country(withName: "Tanzania")

// Get country based on country code e.g: MY, TZ
CountryManager.shared.country(withCode: "MY")

Dependency Graph

Dependecy graph

For swift ui

  • use 3.0.0 and above version

Contributing

Any contribution making project better is welcome.

Authors

*Suryakant Sharma

See also the list of contributors who participated in this project. Thanks from bottom of my heart to inspiration behind Hardeep Singh

License

This project is licensed under the MIT License - see the LICENSE file for details

countrypicker's People

Contributors

adrum avatar ankush-bhatia avatar ashishkakkad8 avatar bekroz avatar d3nzz3l avatar freakdragon avatar ggueno avatar hardeep-singh avatar imgbotapp avatar mike011 avatar musa-almatri avatar nicolaoug avatar senseiphonex avatar sharkesm avatar suryafatbit avatar suryakantsh avatar suryakantsharma avatar vishalkevin11 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  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  avatar  avatar  avatar  avatar

countrypicker's Issues

Instance no longer returned on `present(on:)` in 1.4.1

Describe the bug
In 1.3.2 it was possible to retrieve the instance of the view controller after calling present:

let countryController = CountryPickerWithSectionViewController.presentController(on: self) { ... }

^ that's from the README

Now, the call returns ()

If this is no longer supported, 1.4.1 should have been 2.0.0, as that's a breaking change

No data when countries in Arabic language

No data when countries in Arabic language

// This code is wrong
    func fetchSectionCountries() {
        for section in sections {
            let sectionCountries = countries.filter({ (country) -> Bool in
                return country.countryName.first! == section
            })
            sectionCoutries[section] = sectionCountries
        }
    }

How to use CountryPicker from Objective C project?

I tried to import the pod with CountryPicker into an Objective-C project but I get a bunch of errors.
used @import SKCountryPicker; where I need to use it but then can't access CountryManager shared etc.
How can this be solved?

Thanks.

SPM "Missing contries file path" error.

While using the library with SPM, the error is thrown. The file can not be found under CountryPickerController.bundle. The issue should be related to SPM installation.

After debugging, I see that the file seems to be missing. I will open a PR which should solve the problem.

Favourite group in country code list

Please consider adding a "favorite" section.
where we could set the favorites and it would display in the CountryPickerWithSectionViewController on the top.

Great job on this project!!

EXC_BREAKPOINT Swift runtime failure: Index out of range

Describe the bug

We use the Bugsnag platform to map bugs and a frequent error that happened to our users:

EXC_BREAKPOINT Swift runtime failure: Index out of range

We were unable to replicate it, but we observed that it happens sometime after the user opens the keyboard.

Follow the prints:

Screenshots
Screen Shot 2022-06-24 at 17 21 16

Screen Shot 2022-06-24 at 17 21 38

Smartphone (please complete the following information):

  • Device: Iphone XR
  • OS: iOS 15.5

Getting flag from country code

Hello,
i have used SKcountryPicker in my project in multiple screens such as signUp screen, LoginScreen, EditProfileScreen. So, here the problem is when whenever the country is selected from picker it shows properly after selecting the country in required image and button title. But when i send country code to API and click on submit button of the screen the country code and flag is both set again to default instead of the original selected one

Skype_Video.mp4

Picker not dismissing

Please the country picker doesn't dismiss when i select a country from a search results

White search bar in dark mode

When the search field for the country list is visible the top bar background becomes white.
Isn't it supposed to be black?
How do we change it to black in dark mode?

edit: when the table view controller is opening the top bar background is black, then when it finishes openning it becomes white...

List is Empty

If app download from app store the list of countries is empty. it working fine in developing mode.

Country list not loaded when using SPM

I am using XCODE 11 'Add Swift Package' feature

Country list is not loaded. I debugged and found that country.plist is not loaded. Getting log as "Missing contries file path"

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'Xcode 11->File->Add Swift Package'
  2. Following integration steps to create country button and present country list
  3. Country list is not loaded

Expected behavior
Country list should be loaded

Screenshots
Screenshot 2020-04-28 at 3 45 51 AM

Smartphone (please complete the following information):

  • Device: iPhone11
  • OS: 13.2.2

Using of custom CountryListDataSource doesn't prevent the call of CountryManager.shared `allCountries` method

While using of method presentController of CountryPickerWithSectionViewController (CountryPickerWithSectionViewController.swift row 45) it calls init method of CountryPickerController (CountryPickerController.swift row 113) which creates CountryPickerEngine (CountryPickerController.swift row 115). But when the initiator of CountryPickerEngine (CountryPickerEngine.swift row 15) called the filterOptions parameter calling the initiator of CountryManager.shared because this parameter doesn't sends.

Probably workarounds:

  • change the initiator of CountryPickerEngine to init(countries: [Country] = CountryManager.shared.countries, filterOptions: Set<CountryFilterOption> = [.countryName])
  • add default value for parameter filterOptions when creating the CountryPickerEngine in init method of CountryPickerController
  • change init method of CountryPickerController and method presentController of CountryPickerWithSectionViewController

Add/Remove country

Is there any way to add or remove the country from the list? In my case, I required some selected countries.

How to access SwiftUI views using Swift Package Manager?

Using SPM (CountryPicker 3.0.0) I do not see any of the SwiftUI files contained in CountryPicker/CountryPickeriOS15+

To Reproduce
Add CountryPicker to Xcode via Swift Package Manager:
Screenshot 2024-04-16 at 10 37 59

The folder CountryPicker/CountryPickeriOS15+/CountryPickerSPM is not present in the dependency and I can't access any of the SwiftUI views that exist in the github project:
Screenshot 2024-04-16 at 10 38 17

Expected behavior
I should be able to access the SwiftUI files in CountryPicker/CountryPickeriOS15+/CountryPickerSPM for example CountryPickerView

Searchbar Customization

Hello, I have two questions:

  • My primary color is dark green so I want to change the searchbar icon and title to white
  • I want to translate Search text to spanish "Buscar"

Screenshot 2022-11-04 at 9 56 59 PM

More customization of countries list

More freedom for customization of countries list by custom country manager

This improvement will allow to customize countries list in more ways.

class CustomCountryManager: CountryManager {
    //By overriding this method you can remove any country or add, or customize sorting, or even set your custom country class item
    override open func loadCountries() throws {
           let countryCodes = try! getCountryCodes()
        
           // Clear old loaded countries
           countries.removeAll()
        
           // Request for fresh copy of sorted country list
           let sortedCountries = countryCodes.map { Country(countryCode: $0) }.sorted { $0.countryName < $1.countryName }
                
            //something like this
           sortedCountries.removeFirst()

            countries.append(contentsOf: sortedCountries)
    }

    //By overriding this method you can put any country codes not only from plist of library
    open func getCountryCodes() throws -> [String] {
            return []
    }
}

This will allow to use code like this:

   let countryManager = CustomCountryManager()
   do {
       try countryManager.loadCountries()
   } catch {
       #if DEBUG
           print(error.localizedDescription)
       #endif
   }
   CountryManager.shared = countryManager

For ios 12 selection not working

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Selecting while search

When search is active, it's needed to tap country twice, i don't know if this is a bug but i think the vc should dismiss when a country is selected.

Improve Dark Mode UI

Please improve dark mode UI. Especially the separators, looks too ugly.

Thank you.

About localization-related

Hi, good project, can the following functions be added:

1ใ€Manually switch localization?
2ใ€Manually modify the names of some disputed regions?

Mac Catalyst Support

I am getting "Missing countries plist file from path: ./ -- file:///Users/xxx/Library/Containers/com.xxx.xxx" when trying to run on Catalyst. I am assuming its not supported? Could you please confirm?

Many many thanks for the amazing library. It looks great on iOS.

CountryManager is not loading countries correctly

Hello!

I'm having a problem, it seems like CountryManager is not loading countries correctly in my project. I tried to install by using CocoaPods and SPM and it remains the same. I guess it is a configuration problem.

Console logs:

" Could not load the "US.png" image referenced from a nib in the bundle with identifier "com.myproject.debug" "

As I've tried, actually CountryManager.countries remain empty, so this is not only an image problem.

If there's something I'm missing please, let me know.

removing last selected country is not working

When I use this controller in two different places I want to remove the last selected country but cannot remove it. Can you please provide me with a way to do it.

Thanking you in advance

NSRangeException - out-of-bounds

Error
Terminating app due to uncaught exception 'NSRangeException', reason: 'Attempted to scroll the table view to an out-of-bounds section (18) when there are only 1 sections..

When does it happen ?
It happens when I search "ZA" and there is only one section. When I scroll it breaks. This happens randomly and is not a constant error.

I filter by all three types.

Memory Leak

When the CountryPickerWithSectionViewController is launched and dismissed, loaded country objects are not released. and if you scroll the whole country from beginning to end, it occupies about 170 MB memory.
image

Unable to see check / tick mark for selected country

Describe the bug

  • Unable to see check / tick mark for selected country
    To Reproduce
    Steps to reproduce the behavior:
  1. Open country selection picker
  2. Select country
  3. Close picker
  4. Re-Open country selection picker
  5. Now you see no country is selected

Expected behavior
A clear and concise description of what you expected to happen.

  • Selected country should show check/tick mark

Screenshots
If applicable, add screenshots to help explain your problem.

Screen_Recording_2022-09-30_at_8_01_18_AM_AdobeExpress

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

A way of setting the last selected country

I was wondering if there was a way / if you could make a way to set the last selected country. For example i want to show the picker but first i want to set the last selected country to another country before it is presented. I have already selected US for the country and when i show the controller again i want to set the selected country to UK instead because the field i am editing has UK as the selected country

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.