Skip to content
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ node_modules
.idea
*.iml
.DS_Store
build/
build/
bin
obj
48 changes: 48 additions & 0 deletions index.windows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict';

import { NativeModules } from 'react-native';

const { SelectContact } = NativeModules;

let currentlyOpen = false;

const SelectContactApi = {

selectContactData(field) {
if (currentlyOpen) {
return Promise.reject(new Error('Cannot open the contact selector twice'));
}
currentlyOpen = true;
return SelectContact.openContactSelection(field)
.then(contact => {
currentlyOpen = false;
return contact;
})
.catch(err => {
currentlyOpen = false;
throw err;
});
},

selectContact() {
return SelectContactApi.selectContactData();
},

selectContactPostalAddress() {
return SelectContactApi.selectContactData('Address')
.then(contact => contact ? { contact, selectedAddress: contact.postalAddresses[0]} : null);
},

selectContactPhone() {
return SelectContactApi.selectContactData('PhoneNumber')
.then(contact => contact ? { contact, selectedPhone: contact.phones[0]} : null);
},

selectContactEmail() {
return SelectContactApi.selectContactData('Email')
.then(contact => contact ? { contact, selectedEmail: contact.emails[0]} : null);
}

};

module.exports = SelectContactApi;
286 changes: 286 additions & 0 deletions windows/SelectContact.Shared/Helpers/CountryHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
using System;
using System.Collections.Generic;

namespace CapeCode.SelectContact.Helpers {
internal static class CountryHelper {
public static string TryGetTwoLetterISORegionName(string countryName) {
if (countryName == null) {
return null;
}
countryName = countryName.Trim();
if (countryName == string.Empty) {
return null;
}
if (_countries.TryGetValue(countryName, out CountryInfo countryInfo)) {
return countryInfo.TwoLetterISORegionName;
}
else {
return countryName;
}
}

struct CountryInfo {
public CountryInfo(string twoLetterISORegionName, string threeLetterISORegionName, int id) {
Id = id;
TwoLetterISORegionName = twoLetterISORegionName;
ThreeLetterISORegionName = threeLetterISORegionName;
}
public int Id;
public string TwoLetterISORegionName;
public string ThreeLetterISORegionName;
}

static readonly Dictionary<string, CountryInfo> _countries = new Dictionary<string, CountryInfo>(StringComparer.OrdinalIgnoreCase) {
{"Afghanistan", new CountryInfo("AF", "AFG", 4)},
{"Åland Islands", new CountryInfo("AX", "ALA", 248)},
{"Albania", new CountryInfo("AL", "ALB", 8)},
{"Algeria", new CountryInfo("DZ", "DZA", 12)},
{"American Samoa", new CountryInfo("AS", "ASM", 16)},
{"Andorra", new CountryInfo("AD", "AND", 20)},
{"Angola", new CountryInfo("AO", "AGO", 24)},
{"Anguilla", new CountryInfo("AI", "AIA", 660)},
{"Antarctica", new CountryInfo("AQ", "ATA", 10)},
{"Antigua and Barbuda", new CountryInfo("AG", "ATG", 28)},
{"Argentina", new CountryInfo("AR", "ARG", 32)},
{"Armenia", new CountryInfo("AM", "ARM", 51)},
{"Aruba", new CountryInfo("AW", "ABW", 533)},
{"Australia", new CountryInfo("AU", "AUS", 36)},
{"Austria", new CountryInfo("AT", "AUT", 40)},
{"Azerbaijan", new CountryInfo("AZ", "AZE", 31)},
{"Bahamas", new CountryInfo("BS", "BHS", 44)},
{"Bahrain", new CountryInfo("BH", "BHR", 48)},
{"Bangladesh", new CountryInfo("BD", "BGD", 50)},
{"Barbados", new CountryInfo("BB", "BRB", 52)},
{"Belarus", new CountryInfo("BY", "BLR", 112)},
{"Belgium", new CountryInfo("BE", "BEL", 56)},
{"Belize", new CountryInfo("BZ", "BLZ", 84)},
{"Benin", new CountryInfo("BJ", "BEN", 204)},
{"Bermuda", new CountryInfo("BM", "BMU", 60)},
{"Bhutan", new CountryInfo("BT", "BTN", 64)},
{"Bolivia (Plurinational State of)", new CountryInfo("BO", "BOL", 68)},
{"Plurinational State of Bolivia", new CountryInfo("BO", "BOL", 68)},
{"Bonaire", new CountryInfo("BQ", "BES", 535)},
{"Bosnia and Herzegovina", new CountryInfo("BA", "BIH", 70)},
{"Botswana", new CountryInfo("BW", "BWA", 72)},
{"Bouvet Island", new CountryInfo("BV", "BVT", 74)},
{"Brazil", new CountryInfo("BR", "BRA", 76)},
{"British Indian Ocean Territory", new CountryInfo("IO", "IOT", 86)},
{"Brunei Darussalam", new CountryInfo("BN", "BRN", 96)},
{"Bulgaria", new CountryInfo("BG", "BGR", 100)},
{"Burkina Faso", new CountryInfo("BF", "BFA", 854)},
{"Burundi", new CountryInfo("BI", "BDI", 108)},
{"Cabo Verde", new CountryInfo("CV", "CPV", 132)},
{"Cambodia", new CountryInfo("KH", "KHM", 116)},
{"Cameroon", new CountryInfo("CM", "CMR", 120)},
{"Canada", new CountryInfo("CA", "CAN", 124)},
{"Cayman Islands", new CountryInfo("KY", "CYM", 136)},
{"Central African Republic", new CountryInfo("CF", "CAF", 140)},
{"Chad", new CountryInfo("TD", "TCD", 148)},
{"Chile", new CountryInfo("CL", "CHL", 152)},
{"China", new CountryInfo("CN", "CHN", 156)},
{"Christmas Island", new CountryInfo("CX", "CXR", 162)},
{"Cocos (Keeling) Islands", new CountryInfo("CC", "CCK", 166)},
{"Colombia", new CountryInfo("CO", "COL", 170)},
{"Comoros", new CountryInfo("KM", "COM", 174)},
{"Congo", new CountryInfo("CG", "COG", 178)},
{"Congo (Democratic Republic of the)", new CountryInfo("CD", "COD", 180)},
{"Cook Islands", new CountryInfo("CK", "COK", 184)},
{"Costa Rica", new CountryInfo("CR", "CRI", 188)},
{"Côte d'Ivoire", new CountryInfo("CI", "CIV", 384)},
{"Croatia", new CountryInfo("HR", "HRV", 191)},
{"Cuba", new CountryInfo("CU", "CUB", 192)},
{"Curaçao", new CountryInfo("CW", "CUW", 531)},
{"Cyprus", new CountryInfo("CY", "CYP", 196)},
{"Czech Republic", new CountryInfo("CZ", "CZE", 203)},
{"Denmark", new CountryInfo("DK", "DNK", 208)},
{"Djibouti", new CountryInfo("DJ", "DJI", 262)},
{"Dominica", new CountryInfo("DM", "DMA", 212)},
{"Dominican Republic", new CountryInfo("DO", "DOM", 214)},
{"Ecuador", new CountryInfo("EC", "ECU", 218)},
{"Egypt", new CountryInfo("EG", "EGY", 818)},
{"El Salvador", new CountryInfo("SV", "SLV", 222)},
{"Equatorial Guinea", new CountryInfo("GQ", "GNQ", 226)},
{"Eritrea", new CountryInfo("ER", "ERI", 232)},
{"Estonia", new CountryInfo("EE", "EST", 233)},
{"Ethiopia", new CountryInfo("ET", "ETH", 231)},
{"Falkland Islands (Malvinas)", new CountryInfo("FK", "FLK", 238)},
{"Faroe Islands", new CountryInfo("FO", "FRO", 234)},
{"Fiji", new CountryInfo("FJ", "FJI", 242)},
{"Finland", new CountryInfo("FI", "FIN", 246)},
{"France", new CountryInfo("FR", "FRA", 250)},
{"French Guiana", new CountryInfo("GF", "GUF", 254)},
{"French Polynesia", new CountryInfo("PF", "PYF", 258)},
{"French Southern Territories", new CountryInfo("TF", "ATF", 260)},
{"Gabon", new CountryInfo("GA", "GAB", 266)},
{"Gambia", new CountryInfo("GM", "GMB", 270)},
{"Georgia", new CountryInfo("GE", "GEO", 268)},
{"Germany", new CountryInfo("DE", "DEU", 276)},
{"Ghana", new CountryInfo("GH", "GHA", 288)},
{"Gibraltar", new CountryInfo("GI", "GIB", 292)},
{"Greece", new CountryInfo("GR", "GRC", 300)},
{"Greenland", new CountryInfo("GL", "GRL", 304)},
{"Grenada", new CountryInfo("GD", "GRD", 308)},
{"Guadeloupe", new CountryInfo("GP", "GLP", 312)},
{"Guam", new CountryInfo("GU", "GUM", 316)},
{"Guatemala", new CountryInfo("GT", "GTM", 320)},
{"Guernsey", new CountryInfo("GG", "GGY", 831)},
{"Guinea", new CountryInfo("GN", "GIN", 324)},
{"Guinea-Bissau", new CountryInfo("GW", "GNB", 624)},
{"Guyana", new CountryInfo("GY", "GUY", 328)},
{"Haiti", new CountryInfo("HT", "HTI", 332)},
{"Heard Island and McDonald Islands", new CountryInfo("HM", "HMD", 334)},
{"Holy See", new CountryInfo("VA", "VAT", 336)},
{"Honduras", new CountryInfo("HN", "HND", 340)},
{"Hong Kong", new CountryInfo("HK", "HKG", 344)},
{"Hungary", new CountryInfo("HU", "HUN", 348)},
{"Iceland", new CountryInfo("IS", "ISL", 352)},
{"India", new CountryInfo("IN", "IND", 356)},
{"Indonesia", new CountryInfo("ID", "IDN", 360)},
{"Iran (Islamic Republic of)", new CountryInfo("IR", "IRN", 364)},
{"Iraq", new CountryInfo("IQ", "IRQ", 368)},
{"Ireland", new CountryInfo("IE", "IRL", 372)},
{"Isle of Man", new CountryInfo("IM", "IMN", 833)},
{"Israel", new CountryInfo("IL", "ISR", 376)},
{"Italy", new CountryInfo("IT", "ITA", 380)},
{"Jamaica", new CountryInfo("JM", "JAM", 388)},
{"Japan", new CountryInfo("JP", "JPN", 392)},
{"Jersey", new CountryInfo("JE", "JEY", 832)},
{"Jordan", new CountryInfo("JO", "JOR", 400)},
{"Kazakhstan", new CountryInfo("KZ", "KAZ", 398)},
{"Kenya", new CountryInfo("KE", "KEN", 404)},
{"Kiribati", new CountryInfo("KI", "KIR", 296)},
{"Korea (Democratic People's Republic of)", new CountryInfo("KP", "PRK", 408)},
{"Korea (Republic of)", new CountryInfo("KR", "KOR", 410)},
{"Kuwait", new CountryInfo("KW", "KWT", 414)},
{"Kyrgyzstan", new CountryInfo("KG", "KGZ", 417)},
{"Lao People's Democratic Republic", new CountryInfo("LA", "LAO", 418)},
{"Latvia", new CountryInfo("LV", "LVA", 428)},
{"Lebanon", new CountryInfo("LB", "LBN", 422)},
{"Lesotho", new CountryInfo("LS", "LSO", 426)},
{"Liberia", new CountryInfo("LR", "LBR", 430)},
{"Libya", new CountryInfo("LY", "LBY", 434)},
{"Liechtenstein", new CountryInfo("LI", "LIE", 438)},
{"Lithuania", new CountryInfo("LT", "LTU", 440)},
{"Luxembourg", new CountryInfo("LU", "LUX", 442)},
{"Macao", new CountryInfo("MO", "MAC", 446)},
{"Macedonia (the former Yugoslav Republic of)", new CountryInfo("MK", "MKD", 807)},
{"Madagascar", new CountryInfo("MG", "MDG", 450)},
{"Malawi", new CountryInfo("MW", "MWI", 454)},
{"Malaysia", new CountryInfo("MY", "MYS", 458)},
{"Maldives", new CountryInfo("MV", "MDV", 462)},
{"Mali", new CountryInfo("ML", "MLI", 466)},
{"Malta", new CountryInfo("MT", "MLT", 470)},
{"Marshall Islands", new CountryInfo("MH", "MHL", 584)},
{"Martinique", new CountryInfo("MQ", "MTQ", 474)},
{"Mauritania", new CountryInfo("MR", "MRT", 478)},
{"Mauritius", new CountryInfo("MU", "MUS", 480)},
{"Mayotte", new CountryInfo("YT", "MYT", 175)},
{"Mexico", new CountryInfo("MX", "MEX", 484)},
{"Micronesia (Federated States of)", new CountryInfo("FM", "FSM", 583)},
{"Moldova (Republic of)", new CountryInfo("MD", "MDA", 498)},
{"Monaco", new CountryInfo("MC", "MCO", 492)},
{"Mongolia", new CountryInfo("MN", "MNG", 496)},
{"Montenegro", new CountryInfo("ME", "MNE", 499)},
{"Montserrat", new CountryInfo("MS", "MSR", 500)},
{"Morocco", new CountryInfo("MA", "MAR", 504)},
{"Mozambique", new CountryInfo("MZ", "MOZ", 508)},
{"Myanmar", new CountryInfo("MM", "MMR", 104)},
{"Namibia", new CountryInfo("NA", "NAM", 516)},
{"Nauru", new CountryInfo("NR", "NRU", 520)},
{"Nepal", new CountryInfo("NP", "NPL", 524)},
{"Netherlands", new CountryInfo("NL", "NLD", 528)},
{"New Caledonia", new CountryInfo("NC", "NCL", 540)},
{"New Zealand", new CountryInfo("NZ", "NZL", 554)},
{"Nicaragua", new CountryInfo("NI", "NIC", 558)},
{"Niger", new CountryInfo("NE", "NER", 562)},
{"Nigeria", new CountryInfo("NG", "NGA", 566)},
{"Niue", new CountryInfo("NU", "NIU", 570)},
{"Norfolk Island", new CountryInfo("NF", "NFK", 574)},
{"Northern Mariana Islands", new CountryInfo("MP", "MNP", 580)},
{"Norway", new CountryInfo("NO", "NOR", 578)},
{"Oman", new CountryInfo("OM", "OMN", 512)},
{"Pakistan", new CountryInfo("PK", "PAK", 586)},
{"Palau", new CountryInfo("PW", "PLW", 585)},
{"Palestine", new CountryInfo("PS", "PSE", 275)},
{"Panama", new CountryInfo("PA", "PAN", 591)},
{"Papua New Guinea", new CountryInfo("PG", "PNG", 598)},
{"Paraguay", new CountryInfo("PY", "PRY", 600)},
{"Peru", new CountryInfo("PE", "PER", 604)},
{"Philippines", new CountryInfo("PH", "PHL", 608)},
{"Pitcairn", new CountryInfo("PN", "PCN", 612)},
{"Poland", new CountryInfo("PL", "POL", 616)},
{"Portugal", new CountryInfo("PT", "PRT", 620)},
{"Puerto Rico", new CountryInfo("PR", "PRI", 630)},
{"Qatar", new CountryInfo("QA", "QAT", 634)},
{"Réunion", new CountryInfo("RE", "REU", 638)},
{"Romania", new CountryInfo("RO", "ROU", 642)},
{"Russian Federation", new CountryInfo("RU", "RUS", 643)},
{"Rwanda", new CountryInfo("RW", "RWA", 646)},
{"Saint Barthélemy", new CountryInfo("BL", "BLM", 652)},
{"Saint Helena", new CountryInfo("SH", "SHN", 654)},
{"Saint Kitts and Nevis", new CountryInfo("KN", "KNA", 659)},
{"Saint Lucia", new CountryInfo("LC", "LCA", 662)},
{"Saint Martin (French part)", new CountryInfo("MF", "MAF", 663)},
{"Saint Pierre and Miquelon", new CountryInfo("PM", "SPM", 666)},
{"Saint Vincent and the Grenadines", new CountryInfo("VC", "VCT", 670)},
{"Samoa", new CountryInfo("WS", "WSM", 882)},
{"San Marino", new CountryInfo("SM", "SMR", 674)},
{"Sao Tome and Principe", new CountryInfo("ST", "STP", 678)},
{"Saudi Arabia", new CountryInfo("SA", "SAU", 682)},
{"Senegal", new CountryInfo("SN", "SEN", 686)},
{"Serbia", new CountryInfo("RS", "SRB", 688)},
{"Seychelles", new CountryInfo("SC", "SYC", 690)},
{"Sierra Leone", new CountryInfo("SL", "SLE", 694)},
{"Singapore", new CountryInfo("SG", "SGP", 702)},
{"Sint Maarten (Dutch part)", new CountryInfo("SX", "SXM", 534)},
{"Slovakia", new CountryInfo("SK", "SVK", 703)},
{"Slovenia", new CountryInfo("SI", "SVN", 705)},
{"Solomon Islands", new CountryInfo("SB", "SLB", 90)},
{"Somalia", new CountryInfo("SO", "SOM", 706)},
{"South Africa", new CountryInfo("ZA", "ZAF", 710)},
{"South Georgia and the South Sandwich Islands", new CountryInfo("GS", "SGS", 239)},
{"South Sudan", new CountryInfo("SS", "SSD", 728)},
{"Spain", new CountryInfo("ES", "ESP", 724)},
{"Sri Lanka", new CountryInfo("LK", "LKA", 144)},
{"Sudan", new CountryInfo("SD", "SDN", 729)},
{"Suriname", new CountryInfo("SR", "SUR", 740)},
{"Svalbard and Jan Mayen", new CountryInfo("SJ", "SJM", 744)},
{"Swaziland", new CountryInfo("SZ", "SWZ", 748)},
{"Sweden", new CountryInfo("SE", "SWE", 752)},
{"Switzerland", new CountryInfo("CH", "CHE", 756)},
{"Syrian Arab Republic", new CountryInfo("SY", "SYR", 760)},
{"Taiwan", new CountryInfo("TW", "TWN", 158)},
{"Tajikistan", new CountryInfo("TJ", "TJK", 762)},
{"Tanzania", new CountryInfo("TZ", "TZA", 834)},
{"Thailand", new CountryInfo("TH", "THA", 764)},
{"Timor-Leste", new CountryInfo("TL", "TLS", 626)},
{"Togo", new CountryInfo("TG", "TGO", 768)},
{"Tokelau", new CountryInfo("TK", "TKL", 772)},
{"Tonga", new CountryInfo("TO", "TON", 776)},
{"Trinidad and Tobago", new CountryInfo("TT", "TTO", 780)},
{"Tunisia", new CountryInfo("TN", "TUN", 788)},
{"Turkey", new CountryInfo("TR", "TUR", 792)},
{"Turkmenistan", new CountryInfo("TM", "TKM", 795)},
{"Turks and Caicos Islands", new CountryInfo("TC", "TCA", 796)},
{"Tuvalu", new CountryInfo("TV", "TUV", 798)},
{"Uganda", new CountryInfo("UG", "UGA", 800)},
{"Ukraine", new CountryInfo("UA", "UKR", 804)},
{"United Arab Emirates", new CountryInfo("AE", "ARE", 784)},
{"United Kingdom of Great Britain and Northern Ireland", new CountryInfo("GB", "GBR", 826)},
{"United States of America", new CountryInfo("US", "USA", 840)},
{"United States Minor Outlying Islands", new CountryInfo("UM", "UMI", 581)},
{"Uruguay", new CountryInfo("UY", "URY", 858)},
{"Uzbekistan", new CountryInfo("UZ", "UZB", 860)},
{"Vanuatu", new CountryInfo("VU", "VUT", 548)},
{"Venezuela (Bolivarian Republic of)", new CountryInfo("VE", "VEN", 862)},
{"Viet Nam", new CountryInfo("VN", "VNM", 704)},
{"Virgin Islands (British)", new CountryInfo("VG", "VGB", 92)},
{"Virgin Islands (U.S.)", new CountryInfo("VI", "VIR", 850)},
{"Wallis and Futuna", new CountryInfo("WF", "WLF", 876)},
{"Western Sahara", new CountryInfo("EH", "ESH", 732)},
{"Yemen", new CountryInfo("YE", "YEM", 887)},
{"Zambia", new CountryInfo("ZM", "ZMB", 894)},
{"Zimbabwe", new CountryInfo("ZW", "ZWE", 716)}
};
}
}
15 changes: 15 additions & 0 deletions windows/SelectContact.Shared/SelectContact.Shared.projitems
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>9c36e784-0832-4164-a68c-bd01b2b72211</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>CapeCode.SelectContact</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Helpers\CountryHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SelectContactReactPackage.cs" />
</ItemGroup>
</Project>
13 changes: 13 additions & 0 deletions windows/SelectContact.Shared/SelectContact.Shared.shproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>9c36e784-0832-4164-a68c-bd01b2b72211</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="SelectContact.Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
19 changes: 19 additions & 0 deletions windows/SelectContact.Shared/SelectContactReactPackage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using CapeCode.SelectContact.Modules;
using ReactNative.Bridge;
using ReactNative.Modules.Core;
using ReactNative.UIManager;
using System.Collections.Generic;

namespace CapeCode.SelectContact {
public class SelectContactReactPackage : IReactPackage {
public IReadOnlyList<INativeModule> CreateNativeModules(ReactContext reactContext) {
return new List<INativeModule> {
new SelectContactModule(reactContext),
};
}

public IReadOnlyList<IViewManager> CreateViewManagers(ReactContext reactContext) {
return new List<IViewManager>(0);
}
}
}
Loading