Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'Flag disappears sometimes from picker' issue #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions FlagPhoneNumber.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
0D19301A2293078C002583B1 /* NBPhoneNumberDesc.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D192FEE2293078B002583B1 /* NBPhoneNumberDesc.m */; };
0D19301B2293078C002583B1 /* NBNumberFormat.h in Headers */ = {isa = PBXBuildFile; fileRef = 0D192FEF2293078B002583B1 /* NBNumberFormat.h */; settings = {ATTRIBUTES = (Public, ); }; };
0D19301C2293078C002583B1 /* NBPhoneNumberDefines.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D192FF02293078B002583B1 /* NBPhoneNumberDefines.m */; };
0D19301E2293078C002583B1 /* FPNCountryView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0D192FF32293078B002583B1 /* FPNCountryView.xib */; };
0D19301F2293078C002583B1 /* countryCodes.json in Resources */ = {isa = PBXBuildFile; fileRef = 0D192FF42293078B002583B1 /* countryCodes.json */; };
0D1930202293078C002583B1 /* FlagKit.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0D192FF52293078B002583B1 /* FlagKit.xcassets */; };
0D1930222293078C002583B1 /* FPNNibLoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D192FF82293078B002583B1 /* FPNNibLoadingView.swift */; };
Expand All @@ -51,6 +50,9 @@
0D79D5E22397CB3600DD3E14 /* FPNOBJCCountryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D79D5DC2397CB3600DD3E14 /* FPNOBJCCountryKey.swift */; };
0D79D5E32397CB3600DD3E14 /* FPNUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D79D5DD2397CB3600DD3E14 /* FPNUtils.swift */; };
0DA9CA0B2293E39500723B96 /* FlagPhoneNumber.h in Headers */ = {isa = PBXBuildFile; fileRef = 0D8C7134229296D40026E0C7 /* FlagPhoneNumber.h */; settings = {ATTRIBUTES = (Public, ); }; };
F965B3BF24477F8300C873FF /* CountryListTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F965B3BD24477F8300C873FF /* CountryListTableViewCell.xib */; };
F965B3C024477F8300C873FF /* CountryListTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F965B3BE24477F8300C873FF /* CountryListTableViewCell.swift */; };
F965B3C224477FC200C873FF /* FPNCountryView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F965B3C124477FC100C873FF /* FPNCountryView.xib */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -80,7 +82,6 @@
0D192FEE2293078B002583B1 /* NBPhoneNumberDesc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NBPhoneNumberDesc.m; sourceTree = "<group>"; };
0D192FEF2293078B002583B1 /* NBNumberFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NBNumberFormat.h; sourceTree = "<group>"; };
0D192FF02293078B002583B1 /* NBPhoneNumberDefines.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NBPhoneNumberDefines.m; sourceTree = "<group>"; };
0D192FF32293078B002583B1 /* FPNCountryView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = FPNCountryView.xib; sourceTree = "<group>"; };
0D192FF42293078B002583B1 /* countryCodes.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = countryCodes.json; sourceTree = "<group>"; };
0D192FF52293078B002583B1 /* FlagKit.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = FlagKit.xcassets; sourceTree = "<group>"; };
0D192FF82293078B002583B1 /* FPNNibLoadingView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FPNNibLoadingView.swift; sourceTree = "<group>"; };
Expand All @@ -100,6 +101,9 @@
0D8C7134229296D40026E0C7 /* FlagPhoneNumber.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FlagPhoneNumber.h; sourceTree = "<group>"; };
0D8C7135229296D40026E0C7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
0DF48B3922917047006AB39C /* FlagPhoneNumber.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = FlagPhoneNumber.framework; sourceTree = BUILT_PRODUCTS_DIR; };
F965B3BD24477F8300C873FF /* CountryListTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CountryListTableViewCell.xib; sourceTree = "<group>"; };
F965B3BE24477F8300C873FF /* CountryListTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CountryListTableViewCell.swift; sourceTree = "<group>"; };
F965B3C124477FC100C873FF /* FPNCountryView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = FPNCountryView.xib; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -173,7 +177,7 @@
0D192FF22293078B002583B1 /* Resources */ = {
isa = PBXGroup;
children = (
0D192FF32293078B002583B1 /* FPNCountryView.xib */,
F965B3C124477FC100C873FF /* FPNCountryView.xib */,
0D192FF42293078B002583B1 /* countryCodes.json */,
0D192FF52293078B002583B1 /* FlagKit.xcassets */,
);
Expand Down Expand Up @@ -206,6 +210,8 @@
0DF48B1422916F9F006AB39C /* Sources */ = {
isa = PBXGroup;
children = (
F965B3BE24477F8300C873FF /* CountryListTableViewCell.swift */,
F965B3BD24477F8300C873FF /* CountryListTableViewCell.xib */,
0D79D5C82397CAAA00DD3E14 /* FlagPhoneNumber-Bridging-Header.h */,
0D8C7134229296D40026E0C7 /* FlagPhoneNumber.h */,
0D8C7135229296D40026E0C7 /* Info.plist */,
Expand Down Expand Up @@ -305,9 +311,10 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
0D19301E2293078C002583B1 /* FPNCountryView.xib in Resources */,
F965B3C224477FC200C873FF /* FPNCountryView.xib in Resources */,
0D1930172293078C002583B1 /* NBPhoneNumberMetadata.plist in Resources */,
0D19301F2293078C002583B1 /* countryCodes.json in Resources */,
F965B3BF24477F8300C873FF /* CountryListTableViewCell.xib in Resources */,
0D1930202293078C002583B1 /* FlagKit.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -335,6 +342,7 @@
0D1930282293078C002583B1 /* FPNTextField.swift in Sources */,
0D79D5E02397CB3600DD3E14 /* FPNCountryCode.swift in Sources */,
0D19301A2293078C002583B1 /* NBPhoneNumberDesc.m in Sources */,
F965B3C024477F8300C873FF /* CountryListTableViewCell.swift in Sources */,
0D1930052293078C002583B1 /* NBPhoneNumberUtil.m in Sources */,
0D1930032293078C002583B1 /* NBAsYouTypeFormatter.m in Sources */,
0D79D5E22397CB3600DD3E14 /* FPNOBJCCountryKey.swift in Sources */,
Expand Down
36 changes: 36 additions & 0 deletions Sources/CountryListTableViewCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// CountryListTableViewCell.swift
// FlagPhoneNumber
//
// Created by Ahmed Allam on 4/15/20.
//

import UIKit

class CountryListTableViewCell: UITableViewCell {

@IBOutlet weak var flagLabel: UILabel!
@IBOutlet weak var countryNameLabel: UILabel!
@IBOutlet weak var countryCodeLabel: UILabel!

override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

// Configure the view for the selected state
}



func setup(_ country: FPNCountry, showPhoneCode: Bool) {
flagLabel.text = country.flag
countryNameLabel.text = country.name
if showPhoneCode{
countryCodeLabel.text = country.phoneCode
}
}
}
69 changes: 69 additions & 0 deletions Sources/CountryListTableViewCell.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="15505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15510"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="CountryListTableViewCell" id="KGk-i7-Jjw" customClass="CountryListTableViewCell" customModule="FlagPhoneNumber" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalHuggingPriority="251" text="Slovenia" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="CSR-mi-rvY">
<rect key="frame" x="76" y="11.5" width="160" height="21"/>
<constraints>
<constraint firstAttribute="height" constant="21" id="ZiL-Ve-hAJ"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="+386" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Qsy-FV-gJo">
<rect key="frame" x="248" y="11.5" width="42" height="21"/>
<constraints>
<constraint firstAttribute="height" constant="21" id="dW1-in-ES5"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.60784313729999995" green="0.60784313729999995" blue="0.60784313729999995" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="7zS-0V-3Kv">
<rect key="frame" x="30" y="7.5" width="29" height="29"/>
<constraints>
<constraint firstAttribute="height" constant="29" id="J73-cE-rVD"/>
<constraint firstAttribute="width" constant="29" id="SyM-u2-fdT"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="CSR-mi-rvY" secondAttribute="bottom" constant="11.5" id="3AA-j0-NXx"/>
<constraint firstItem="Qsy-FV-gJo" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="11.5" id="E40-pM-alN"/>
<constraint firstItem="7zS-0V-3Kv" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="7.5" id="Fxx-EE-3jS"/>
<constraint firstAttribute="bottom" secondItem="7zS-0V-3Kv" secondAttribute="bottom" constant="7.5" id="H6C-o1-aqN"/>
<constraint firstItem="CSR-mi-rvY" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="11.5" id="UaW-Yi-QzD"/>
<constraint firstItem="Qsy-FV-gJo" firstAttribute="leading" secondItem="CSR-mi-rvY" secondAttribute="trailing" constant="12" id="XYe-si-f1c"/>
<constraint firstItem="CSR-mi-rvY" firstAttribute="leading" secondItem="7zS-0V-3Kv" secondAttribute="trailing" constant="17" id="aMo-e7-zUy"/>
<constraint firstAttribute="bottom" secondItem="Qsy-FV-gJo" secondAttribute="bottom" constant="11.5" id="dI1-dW-rGT"/>
<constraint firstItem="7zS-0V-3Kv" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="30" id="hRO-Yk-utr"/>
<constraint firstAttribute="trailing" secondItem="Qsy-FV-gJo" secondAttribute="trailing" constant="30" id="m2o-we-e8g"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="countryCodeLabel" destination="Qsy-FV-gJo" id="sjh-dg-P3c"/>
<outlet property="countryNameLabel" destination="CSR-mi-rvY" id="a70-ha-jz8"/>
<outlet property="flagLabel" destination="7zS-0V-3Kv" id="CsN-74-Xte"/>
</connections>
<point key="canvasLocation" x="132" y="147"/>
</tableViewCell>
</objects>
</document>
46 changes: 25 additions & 21 deletions Sources/FPNCountry.swift
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import UIKit

public struct FPNCountry: Equatable {

public var code: FPNCountryCode
public var name: String
public var phoneCode: String
var flag: UIImage?

init(code: String, name: String, phoneCode: String) {
self.name = name
self.phoneCode = phoneCode
self.code = FPNCountryCode(rawValue: code)!

if let flag = UIImage(named: code, in: Bundle.FlagIcons, compatibleWith: nil) {
self.flag = flag
} else {
self.flag = UIImage(named: "unknown", in: Bundle.FlagIcons, compatibleWith: nil)
}
}

static public func ==(lhs: FPNCountry, rhs: FPNCountry) -> Bool {
return lhs.code == rhs.code
}

public var code: FPNCountryCode
public var name: String
public var phoneCode: String
var flag: String = ""

init(code: String, name: String, phoneCode: String) {
self.name = name
self.phoneCode = phoneCode
self.code = FPNCountryCode(rawValue: code)!
flag = getFlag(country: code)
}

static public func ==(lhs: FPNCountry, rhs: FPNCountry) -> Bool {
return lhs.code == rhs.code
}

func getFlag(country:String) -> String {
let base : UInt32 = 127397
var s = ""
for v in country.unicodeScalars {
s.unicodeScalars.append(UnicodeScalar(base + v.value)!)
}
return String(s)
}
}
Loading