diff --git a/.gitignore b/.gitignore index c646d1e..40ec56e 100644 --- a/.gitignore +++ b/.gitignore @@ -31,4 +31,6 @@ node_modules .idea *.iml .DS_Store -build/ \ No newline at end of file +build/ +bin +obj diff --git a/index.windows.js b/index.windows.js new file mode 100644 index 0000000..1a219eb --- /dev/null +++ b/index.windows.js @@ -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; \ No newline at end of file diff --git a/windows/SelectContact.Shared/Helpers/CountryHelper.cs b/windows/SelectContact.Shared/Helpers/CountryHelper.cs new file mode 100644 index 0000000..bc8c65b --- /dev/null +++ b/windows/SelectContact.Shared/Helpers/CountryHelper.cs @@ -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 _countries = new Dictionary(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)} + }; + } +} \ No newline at end of file diff --git a/windows/SelectContact.Shared/SelectContact.Shared.projitems b/windows/SelectContact.Shared/SelectContact.Shared.projitems new file mode 100644 index 0000000..4adf649 --- /dev/null +++ b/windows/SelectContact.Shared/SelectContact.Shared.projitems @@ -0,0 +1,15 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + 9c36e784-0832-4164-a68c-bd01b2b72211 + + + CapeCode.SelectContact + + + + + + \ No newline at end of file diff --git a/windows/SelectContact.Shared/SelectContact.Shared.shproj b/windows/SelectContact.Shared/SelectContact.Shared.shproj new file mode 100644 index 0000000..a9284e0 --- /dev/null +++ b/windows/SelectContact.Shared/SelectContact.Shared.shproj @@ -0,0 +1,13 @@ + + + + 9c36e784-0832-4164-a68c-bd01b2b72211 + 14.0 + + + + + + + + diff --git a/windows/SelectContact.Shared/SelectContactReactPackage.cs b/windows/SelectContact.Shared/SelectContactReactPackage.cs new file mode 100644 index 0000000..553d5c8 --- /dev/null +++ b/windows/SelectContact.Shared/SelectContactReactPackage.cs @@ -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 CreateNativeModules(ReactContext reactContext) { + return new List { + new SelectContactModule(reactContext), + }; + } + + public IReadOnlyList CreateViewManagers(ReactContext reactContext) { + return new List(0); + } + } +} \ No newline at end of file diff --git a/windows/SelectContact/Extensions/ModuleExtensions.cs b/windows/SelectContact/Extensions/ModuleExtensions.cs new file mode 100644 index 0000000..26dd0af --- /dev/null +++ b/windows/SelectContact/Extensions/ModuleExtensions.cs @@ -0,0 +1,21 @@ +using Newtonsoft.Json.Linq; +using ReactNative.Bridge; +using ReactNative.Modules.Core; +using System; +using Windows.ApplicationModel.Core; +using Windows.UI.Core; + +namespace CapeCode.SelectContact.Extensions { + + public static class ModuleExtensions { + + public static void SendEvent(this ReactContextNativeModuleBase module, string eventName, JObject parameters) { + module.Context.GetJavaScriptModule() + .emit(eventName, parameters); + } + + public static async void RunOnDispatcher(this ReactContextNativeModuleBase module, DispatchedHandler action) { + await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, action).AsTask().ConfigureAwait(false); + } + } +} \ No newline at end of file diff --git a/windows/SelectContact/Modules/SelectContactModule.cs b/windows/SelectContact/Modules/SelectContactModule.cs new file mode 100644 index 0000000..c3ffacd --- /dev/null +++ b/windows/SelectContact/Modules/SelectContactModule.cs @@ -0,0 +1,62 @@ +using CapeCode.SelectContact.Extensions; +using CapeCode.SelectContact.Helpers; +using ReactNative.Bridge; +using System; +using System.Linq; +using Windows.ApplicationModel.Contacts; + +namespace CapeCode.SelectContact.Modules { + + public class SelectContactModule : ReactContextNativeModuleBase { + + public SelectContactModule(ReactContext reactContext) + : base(reactContext) { + } + + public override string Name => "SelectContact"; + + [ReactMethod] + public void openContactSelection(ContactFieldType? fieldType, IPromise promise) { + try { + this.RunOnDispatcher(async () => { + try { + var contactPicker = new ContactPicker(); + if (fieldType != null) { + contactPicker.SelectionMode = ContactSelectionMode.Fields; + contactPicker.DesiredFieldsWithContactFieldType.Add(fieldType.Value); + } + Contact contact = await contactPicker.PickContactAsync(); + promise.Resolve(contact == null ? null : new { + recordId = contact.Id, + name = contact.Name, + givenName = contact.FirstName, + middleName = contact.MiddleName, + familyName = contact.LastName, + phones = contact.Phones?.Select(x => new { + number = x.Number, + type = x.Kind.ToString(), + }), + emails = contact.Emails?.Select(x => new { + address = x.Address, + type = x.Kind.ToString(), + }), + postalAddresses = contact.Addresses?.Select(x => new { + street = x.StreetAddress, + city = x.Locality, + state = x.Region, + postalCode = x.PostalCode, + isoCountryCode = CountryHelper.TryGetTwoLetterISORegionName(x.Country), + }), + }); + } + catch (Exception ex) { + promise.Reject(ex); + } + }); + } + catch (Exception ex) { + promise.Reject(ex); + } + } + } +} \ No newline at end of file diff --git a/windows/SelectContact/Properties/AssemblyInfo.cs b/windows/SelectContact/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..205e384 --- /dev/null +++ b/windows/SelectContact/Properties/AssemblyInfo.cs @@ -0,0 +1,29 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SelectContact")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SelectContact")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: ComVisible(false)] \ No newline at end of file diff --git a/windows/SelectContact/Properties/SelectContact.rd.xml b/windows/SelectContact/Properties/SelectContact.rd.xml new file mode 100644 index 0000000..60c9701 --- /dev/null +++ b/windows/SelectContact/Properties/SelectContact.rd.xml @@ -0,0 +1,33 @@ + + + + + + + + + diff --git a/windows/SelectContact/SelectContact.csproj b/windows/SelectContact/SelectContact.csproj new file mode 100644 index 0000000..27e4df3 --- /dev/null +++ b/windows/SelectContact/SelectContact.csproj @@ -0,0 +1,151 @@ + + + + + Debug + AnyCPU + {F82B445E-3B94-47C4-BE92-CB8DB2318CCB} + Library + Properties + CapeCode.SelectContact + CapeCode.SelectContact + en-US + UAP + 10.0.17134.0 + 10.0.15063.0 + 14 + 512 + {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + prompt + 4 + + + x86 + true + bin\x86\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + false + prompt + + + x86 + bin\x86\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + false + prompt + + + ARM + true + bin\ARM\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + false + prompt + + + ARM + bin\ARM\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + false + prompt + + + ARM64 + true + bin\ARM64\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + false + prompt + + + ARM64 + bin\ARM64\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + false + prompt + + + x64 + true + bin\x64\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + false + prompt + + + x64 + bin\x64\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + false + prompt + + + PackageReference + + + + + + + + + + 6.2.3 + + + + + {C7673AD5-E3AA-468C-A5FD-FA38154E205C} + ReactNative + + + + + 14.0 + + + + \ No newline at end of file