Skip to content

Commit

Permalink
Merge pull request #35 from JNDisrupter/development
Browse files Browse the repository at this point in the history
IOS 15 Upgrade
  • Loading branch information
jayelzaghmoutt authored Apr 18, 2022
2 parents 6d4221e + 96fa5d4 commit 71cbf35
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 42 deletions.
11 changes: 9 additions & 2 deletions Example/JNPhoneNumberView/JNCountryPickerExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,24 @@ class JNCountryPickerExample: UIViewController, JNCountryPickerViewControllerDel

/**
Did Select Country
- Parameter controller: JN Country Picker ViewController
- Parameter country: country as JNCountry.
*/
func countryPickerViewController(didSelectCountry country: JNCountry) {
func countryPickerViewController(_ controller: JNCountryPickerViewController, didSelectCountry country: JNCountry) {

// update Selected Country
self.selectedCountry = country

self.selectedCountryInfoLabel.text = " Country Name: \(country.name) \n Country Dial Code: \(country.dialCode) \n Country Code: \(country.code)"
}

func countryPickerViewControllerLoadCountryList(completion: ([JNCountry]) -> Void, errorCompletion: (NSError) -> Void) {
/**
Load country list
- Parameter controller: JN Country Picker ViewController
- Parameter completion: completion block
- Parameter errorCompletion: errorCompletion
*/
func countryPickerViewControllerLoadCountryList(_ controller: JNCountryPickerViewController, completion: @escaping ([JNCountry]) -> Void, errorCompletion: @escaping (NSError) -> Void) {
completion([])
}
}
15 changes: 10 additions & 5 deletions Example/JNPhoneNumberView/JNPhoneNumberViewExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,18 @@ extension JNPhoneNumberViewExample: JNPhoneNumberViewDelegate {

/**
Get presenter view controller
- Parameter phoneNumberView: Phone number view
- Returns: presenter view controller
*/
func phoneNumberViewGetPresenterViewController() -> UIViewController {
func phoneNumberView(getPresenterViewControllerFor phoneNumberView: JNPhoneNumberView) -> UIViewController {
return self
}

/**
Get country code picker attributes
- Parameter phoneNumberView: Phone number view
*/
func phoneNumberViewGetCountryPickerAttributes() -> JNCountryPickerConfiguration {
func phoneNumberView(getCountryPickerAttributesFor phoneNumberView: JNPhoneNumberView) -> JNCountryPickerConfiguration {
let configuration = JNCountryPickerConfiguration()
configuration.pickerLanguage = .en
configuration.tableCellInsets = UIEdgeInsets(top: 10.0, left: 10.0, bottom: 10.0, right: 10.0)
Expand All @@ -66,8 +68,9 @@ extension JNPhoneNumberViewExample: JNPhoneNumberViewDelegate {
Did change text
- Parameter nationalNumber: National phone number
- Parameter country: Number country info
- Parameter phoneNumberView: Phone number view
*/
func phoneNumberView(didChangeText nationalNumber: String, country: JNCountry) {
func phoneNumberView(didChangeText nationalNumber: String, country: JNCountry, forPhoneNumberView phoneNumberView: JNPhoneNumberView) {
self.phoneNumberLabel.text = "International Phone Number: \n \(self.phoneNumberView.getDialCode() + nationalNumber)"

self.phoneNumberView.setViewConfiguration(self.getConfigration())
Expand All @@ -78,8 +81,9 @@ extension JNPhoneNumberViewExample: JNPhoneNumberViewDelegate {
- Parameter nationalNumber: National phone number
- Parameter country: Number country info
- Parameter isValidPhoneNumber: Is valid phone number flag as bool
- Parameter phoneNumberView: Phone number view
*/
func phoneNumberView(didEndEditing nationalNumber: String, country: JNCountry, isValidPhoneNumber: Bool) {
func phoneNumberView(didEndEditing nationalNumber: String, country: JNCountry, isValidPhoneNumber: Bool, forPhoneNumberView phoneNumberView: JNPhoneNumberView) {
let validationMessage = isValidPhoneNumber ? "Valid Phone Number" : "Invalid Phone Number"
self.phoneNumberLabel.text = "International Phone Number: \n \(self.phoneNumberView.getDialCode() + nationalNumber) \n \(validationMessage)"

Expand All @@ -90,8 +94,9 @@ extension JNPhoneNumberViewExample: JNPhoneNumberViewDelegate {
Country Did Changed
- Parameter country: New Selected Country
- Parameter isValidPhoneNumber: Is valid phone number flag as bool
- Parameter phoneNumberView: Phone number view
*/
func phoneNumberView(countryDidChanged country: JNCountry, isValidPhoneNumber: Bool) {
func phoneNumberView(countryDidChanged country: JNCountry, isValidPhoneNumber: Bool, forPhoneNumberView phoneNumberView: JNPhoneNumberView) {
let validationMessage = isValidPhoneNumber ? "Valid Phone Number" : "Invalid Phone Number"
self.phoneNumberLabel.text = "International Phone Number: \n \(self.phoneNumberView.getPhoneNumber()) \n \(validationMessage)"

Expand Down
2 changes: 1 addition & 1 deletion JNPhoneNumberView.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Pod::Spec.new do |s|
s.name = "JNPhoneNumberView"
s.version = "1.0.16"
s.version = "1.1.0"
s.summary = "Phone Number Validation with country dial code picker"
s.description = "A view to show the country dial code and the phone number, you can click on the dial code and select another country from the countries picker, this view has a delegate methods to pass the international number and validity of it."
s.homepage = "https://github.com/JNDisrupter"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,30 @@ import UIKit
// If presented.
if self.isPresentedModally {

// Set naviation bar colors
if #available(iOS 13.0, *) {

// Setup appearance
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = self.pickerConfiguration.navigationBarColor
appearance.shadowImage = nil
appearance.titleTextAttributes = self.pickerConfiguration.navigationBarTitleTextAttributes

// Set scroll edge and standard appearance
self.navigationController?.navigationBar.scrollEdgeAppearance = appearance
self.navigationController?.navigationBar.standardAppearance = appearance

} else {

// Setup custom navigation bar
self.navigationController?.navigationBar.shadowImage = nil
self.navigationController?.navigationBar.titleTextAttributes = self.pickerConfiguration.navigationBarTitleTextAttributes
}

// Setup custom navigation bar
self.navigationController?.navigationBar.barTintColor = self.pickerConfiguration.navigationBarColor
self.navigationController?.navigationBar.isTranslucent = false
self.navigationController?.navigationBar.tintColor = self.pickerConfiguration.naigationBarTintColor
self.navigationController?.navigationBar.titleTextAttributes = self.pickerConfiguration.navigationBarTitleTextAttributes

// Set left bar button item
self.setupCloseBarButtonItem()
Expand Down Expand Up @@ -234,7 +254,7 @@ import UIKit
guard let selectedItem = self.viewModel.getSelectedItem() else { return }

// call delegate did select country code
self.delegate?.countryPickerViewController(didSelectCountry: selectedItem)
self.delegate?.countryPickerViewController(self, didSelectCountry: selectedItem)

// Dismiss view controller
if self.isPresentedModally {
Expand Down Expand Up @@ -287,7 +307,7 @@ import UIKit
if let dataSourceDelegate = self.dataSourceDelegate {

// Call delegate
dataSourceDelegate.countryPickerViewControllerLoadCountryList(completion: { [weak self] countryList in
dataSourceDelegate.countryPickerViewControllerLoadCountryList(self, completion: { [weak self] countryList in

// Check if empty
if countryList.isEmpty {
Expand Down Expand Up @@ -363,18 +383,20 @@ import UIKit

/**
Did Select Country
- Parameter controller: JN Country Picker ViewController
- Parameter country: country as JNCountry.
*/
@objc func countryPickerViewController(didSelectCountry country: JNCountry)
@objc func countryPickerViewController(_ controller: JNCountryPickerViewController, didSelectCountry country: JNCountry)
}

/// JN Country Picker View Controller Delegate
@objc public protocol JNCountryPickerViewControllerDataSourceDelegate: NSObjectProtocol {

/**
Load country list
- Parameter controller: JN Country Picker ViewController
- Parameter completion: completion block
- Parameter errorCompletion: errorCompletion
*/
@objc func countryPickerViewControllerLoadCountryList(completion: @escaping ([JNCountry]) -> Void, errorCompletion: @escaping (NSError) -> Void)
@objc func countryPickerViewControllerLoadCountryList(_ controller: JNCountryPickerViewController, completion: @escaping ([JNCountry]) -> Void, errorCompletion: @escaping (NSError) -> Void)
}
40 changes: 24 additions & 16 deletions JNPhoneNumberView/Classes/JNPhoneNumberView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public class JNPhoneNumberView: UIView, UITextFieldDelegate {
let countriesPickerViewController = JNCountryPickerViewController()

// Set picker attributes
countriesPickerViewController.pickerConfiguration = delegate.phoneNumberViewGetCountryPickerAttributes()
countriesPickerViewController.pickerConfiguration = delegate.phoneNumberView(getCountryPickerAttributesFor: self)

// Set data source delegate
countriesPickerViewController.dataSourceDelegate = self
Expand All @@ -354,7 +354,7 @@ public class JNPhoneNumberView: UIView, UITextFieldDelegate {
countriesPickerViewController.selectedCountry = self.selectedCountry

// Presenter view controller
let presenterViewController = delegate.phoneNumberViewGetPresenterViewController()
let presenterViewController = delegate.phoneNumberView(getPresenterViewControllerFor: self)

// Init navigation controller and present it
let navigationController = UINavigationController(rootViewController: countriesPickerViewController)
Expand Down Expand Up @@ -416,7 +416,7 @@ public class JNPhoneNumberView: UIView, UITextFieldDelegate {
public func textFieldDidEndEditing(_ textField: UITextField) {

// Call delegate
self.delegate?.phoneNumberView(didEndEditing: (self.textField.text ?? ""), country: self.selectedCountry, isValidPhoneNumber: self.isValidPhoneNumber())
self.delegate?.phoneNumberView(didEndEditing: (self.textField.text ?? ""), country: self.selectedCountry, isValidPhoneNumber: self.isValidPhoneNumber(), forPhoneNumberView: self)
}

/**
Expand All @@ -425,7 +425,7 @@ public class JNPhoneNumberView: UIView, UITextFieldDelegate {
@IBAction func textFieldDidChangeText(_ sender: Any) {

// Call delegate
self.delegate?.phoneNumberView(didChangeText: (self.textField.text ?? ""), country: self.selectedCountry)
self.delegate?.phoneNumberView(didChangeText: (self.textField.text ?? ""), country: self.selectedCountry, forPhoneNumberView: self)
}

// MARK: - Validation
Expand Down Expand Up @@ -490,9 +490,10 @@ extension JNPhoneNumberView: JNCountryPickerViewControllerDelegate {

/**
Did Select Country
- Parameter controller: JN Country Picker ViewController
- Parameter country: country as JNCountry.
*/
public func countryPickerViewController(didSelectCountry country: JNCountry) {
public func countryPickerViewController(_ controller: JNCountryPickerViewController, didSelectCountry country: JNCountry) {

// Set selected country
self.selectedCountry = country
Expand All @@ -501,25 +502,26 @@ extension JNPhoneNumberView: JNCountryPickerViewControllerDelegate {
self.setupCountyLabels()

// Call delegate
self.delegate?.phoneNumberView(countryDidChanged: country, isValidPhoneNumber: self.isValidPhoneNumber())
self.delegate?.phoneNumberView(countryDidChanged: country, isValidPhoneNumber: self.isValidPhoneNumber(), forPhoneNumberView: self)
}
}

/// Country Code Data Source Delegate
extension JNPhoneNumberView: JNCountryPickerViewControllerDataSourceDelegate {

/**
Get country code list
Load country list
- Parameter controller: JN Country Picker ViewController
- Parameter completion: completion block
- Parameter errorCompletion
- Parameter errorCompletion: errorCompletion
*/
public func countryPickerViewControllerLoadCountryList(completion: @escaping ([JNCountry]) -> Void, errorCompletion: @escaping (NSError) -> Void) {
public func countryPickerViewControllerLoadCountryList(_ controller: JNCountryPickerViewController, completion: @escaping ([JNCountry]) -> Void, errorCompletion: @escaping (NSError) -> Void) {

// Data source delegate
if let dataSourceDelegate = self.dataSourceDelegate {

// Call phone view data source delegate
dataSourceDelegate.countryPickerViewControllerLoadCountryList(completion: { countryList in
dataSourceDelegate.countryPickerViewControllerLoadCountryList(self, completion: { countryList in

// Call completion
completion(countryList)
Expand All @@ -542,45 +544,51 @@ extension JNPhoneNumberView: JNCountryPickerViewControllerDataSourceDelegate {

/**
Get presenter view controller
- Parameter phoneNumberView: Phone number view
- Returns: presenter view controller
*/
func phoneNumberViewGetPresenterViewController() -> UIViewController
func phoneNumberView(getPresenterViewControllerFor phoneNumberView: JNPhoneNumberView) -> UIViewController

/**
Get country picker configuration
- Parameter phoneNumberView: Phone number view
*/
func phoneNumberViewGetCountryPickerAttributes() -> JNCountryPickerConfiguration
func phoneNumberView(getCountryPickerAttributesFor phoneNumberView: JNPhoneNumberView) -> JNCountryPickerConfiguration

/**
Did change text
- Parameter nationalNumber: National phone number
- Parameter country: Number country info
- Parameter phoneNumberView: Phone number view
*/
func phoneNumberView(didChangeText nationalNumber: String, country: JNCountry)
func phoneNumberView(didChangeText nationalNumber: String, country: JNCountry, forPhoneNumberView phoneNumberView: JNPhoneNumberView)

/**
Did end editing
- Parameter nationalNumber: National phone number
- Parameter country: Number country info
- Parameter isValidPhoneNumber: Is valid phone number flag as bool
- Parameter phoneNumberView: Phone number view
*/
func phoneNumberView(didEndEditing nationalNumber: String, country: JNCountry, isValidPhoneNumber: Bool)
func phoneNumberView(didEndEditing nationalNumber: String, country: JNCountry, isValidPhoneNumber: Bool, forPhoneNumberView phoneNumberView: JNPhoneNumberView)

/**
Country Did Changed
- Parameter country: New Selected Country
- Parameter isValidPhoneNumber: Is valid phone number flag as bool
- Parameter phoneNumberView: Phone number view
*/
func phoneNumberView(countryDidChanged country: JNCountry, isValidPhoneNumber: Bool)
func phoneNumberView(countryDidChanged country: JNCountry, isValidPhoneNumber: Bool, forPhoneNumberView phoneNumberView: JNPhoneNumberView)
}

/// JN Phone Number View Delegate
@objc public protocol JNPhoneNumberViewDataSourceDelegate: NSObjectProtocol {

/**
Load country list
- Parameter phoneNumberView: Phone number view
- Parameter completion: completion block
- Parameter errorCompletion: errorCompletion
*/
@objc func countryPickerViewControllerLoadCountryList(completion: @escaping ([JNCountry]) -> Void, errorCompletion: @escaping (NSError) -> Void)
@objc func countryPickerViewControllerLoadCountryList(_ phoneNumberView: JNPhoneNumberView, completion: @escaping ([JNCountry]) -> Void, errorCompletion: @escaping (NSError) -> Void)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import Foundation
import libPhoneNumber_iOS

/// JN Country Util
@objc public class JNCountryUtil: NSObject {
public class JNCountryUtil {

/**
Generate Flag
- Parameter countryCode: country code
- Returns: flag as string
*/
@objc public class func generateFlag(from countryCode: String) -> String {
public class func generateFlag(from countryCode: String) -> String {
let base : UInt32 = 127397
var s = ""
for uincodeScalar in countryCode.uppercased().unicodeScalars {
Expand All @@ -31,7 +31,7 @@ import libPhoneNumber_iOS
- Parameter regionCode: region code as string
- Returns: Country as JNCountry
*/
@objc public class func generateDialCode(for regionCode: String) -> JNCountry? {
public class func generateDialCode(for regionCode: String) -> JNCountry? {

// Init meta data helper
let metaDataHelper = NBMetadataHelper()
Expand All @@ -56,7 +56,7 @@ import libPhoneNumber_iOS
- Parameter phoneNumber: phone number as NBPhoneNumber
- Returns: Country as JNCountry
*/
@objc public class func generateCountryCode(for phoneNumber: NBPhoneNumber) -> JNCountry? {
public class func generateCountryCode(for phoneNumber: NBPhoneNumber) -> JNCountry? {

// Modified dial code
var modifiedDialCode = phoneNumber.countryCode.description
Expand Down
Loading

0 comments on commit 71cbf35

Please sign in to comment.