diff --git a/index.js b/index.js index 290919c..2270acc 100644 --- a/index.js +++ b/index.js @@ -51,19 +51,44 @@ function pick(opts) { return RNDocumentPicker.pick(opts); } + +const Types = { + mimeTypes: { + 'allFiles': '*/*', + 'images': 'image/*', + 'plainText': 'text/plain', + 'audio': 'audio/*', + 'pdf': 'application/pdf', + }, + utis: { + 'allFiles': 'public.content', + 'images': 'public.image', + 'plainText': 'public.plain-text', + 'audio': 'public.audio', + 'pdf': 'com.adobe.pdf', + }, + extensions: { + 'allFiles': '*', + 'images': '.png .jpg .jpeg', + 'plainText': '.txt', + 'audio': '.adts .adt .aac .aif .aifc .aiff .au .snd .mid .midi .rmi .mp3 .mp2 .m3u .m4a .wav .wma .wax .asf .3g2 .3gp .m4b .mp4', + 'pdf': '.pdf', + } +}; + +const PlatformTypes = { + android: Types.mimeTypes, + ios: Types.utis, + windows: Types.extensions +}; + export default class DocumentPicker { /** * Android requires mime types, iOS is a bit more complicated: * * @see https://developer.apple.com/library/ios/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html */ - static types = { - allFiles: Platform.OS === 'ios' ? 'public.content' : '*/*', - images: Platform.OS === 'ios' ? 'public.image' : 'image/*', - plainText: Platform.OS === 'ios' ? 'public.plain-text' : 'text/plain', - audio: Platform.OS === 'ios' ? 'public.audio' : 'audio/*', - pdf: Platform.OS === 'ios' ? 'com.adobe.pdf' : 'application/pdf', - }; + static types = PlatformTypes[Platform.OS] || Types.mimeTypes static pick(opts) { opts = opts || {}; diff --git a/windows/RNDocumentPicker.sln b/windows/RNDocumentPicker.sln index 8a87817..408b166 100644 --- a/windows/RNDocumentPicker.sln +++ b/windows/RNDocumentPicker.sln @@ -1,8 +1,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26730.16 +VisualStudioVersion = 15.0.26730.3 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RNDocumentPicker", "RNDocumentPicker\RNDocumentPicker.csproj", "{811E4A06-ADAF-B342-8F02-43713D65B1B0}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RNDocumentPicker", "RNDocumentPicker\RNDocumentPicker.csproj", "{GF11038F0-88E5-11E7-BA7C-E36C7490591B}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactNative", "..\node_modules\react-native-windows\ReactWindows\ReactNative\ReactNative.csproj", "{C7673AD5-E3AA-468C-A5FD-FA38154E205C}" EndProject @@ -27,24 +27,24 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {811E4A06-ADAF-B342-8F02-43713D65B1B0}.Debug|ARM.ActiveCfg = Debug|ARM - {811E4A06-ADAF-B342-8F02-43713D65B1B0}.Debug|ARM.Build.0 = Debug|ARM - {811E4A06-ADAF-B342-8F02-43713D65B1B0}.Debug|x64.ActiveCfg = Debug|x64 - {811E4A06-ADAF-B342-8F02-43713D65B1B0}.Debug|x64.Build.0 = Debug|x64 - {811E4A06-ADAF-B342-8F02-43713D65B1B0}.Debug|x86.ActiveCfg = Debug|x86 - {811E4A06-ADAF-B342-8F02-43713D65B1B0}.Debug|x86.Build.0 = Debug|x86 - {811E4A06-ADAF-B342-8F02-43713D65B1B0}.Development|ARM.ActiveCfg = Development|ARM - {811E4A06-ADAF-B342-8F02-43713D65B1B0}.Development|ARM.Build.0 = Development|ARM - {811E4A06-ADAF-B342-8F02-43713D65B1B0}.Development|x64.ActiveCfg = Development|x64 - {811E4A06-ADAF-B342-8F02-43713D65B1B0}.Development|x64.Build.0 = Development|x64 - {811E4A06-ADAF-B342-8F02-43713D65B1B0}.Development|x86.ActiveCfg = Development|x86 - {811E4A06-ADAF-B342-8F02-43713D65B1B0}.Development|x86.Build.0 = Development|x86 - {811E4A06-ADAF-B342-8F02-43713D65B1B0}.Release|ARM.ActiveCfg = Release|ARM - {811E4A06-ADAF-B342-8F02-43713D65B1B0}.Release|ARM.Build.0 = Release|ARM - {811E4A06-ADAF-B342-8F02-43713D65B1B0}.Release|x64.ActiveCfg = Release|x64 - {811E4A06-ADAF-B342-8F02-43713D65B1B0}.Release|x64.Build.0 = Release|x64 - {811E4A06-ADAF-B342-8F02-43713D65B1B0}.Release|x86.ActiveCfg = Release|x86 - {811E4A06-ADAF-B342-8F02-43713D65B1B0}.Release|x86.Build.0 = Release|x86 + {GF11038F0-88E5-11E7-BA7C-E36C7490591B}.Debug|ARM.ActiveCfg = Debug|ARM + {GF11038F0-88E5-11E7-BA7C-E36C7490591B}.Debug|ARM.Build.0 = Debug|ARM + {GF11038F0-88E5-11E7-BA7C-E36C7490591B}.Debug|x64.ActiveCfg = Debug|x64 + {GF11038F0-88E5-11E7-BA7C-E36C7490591B}.Debug|x64.Build.0 = Debug|x64 + {GF11038F0-88E5-11E7-BA7C-E36C7490591B}.Debug|x86.ActiveCfg = Debug|x86 + {GF11038F0-88E5-11E7-BA7C-E36C7490591B}.Debug|x86.Build.0 = Debug|x86 + {GF11038F0-88E5-11E7-BA7C-E36C7490591B}.Development|ARM.ActiveCfg = Development|ARM + {GF11038F0-88E5-11E7-BA7C-E36C7490591B}.Development|ARM.Build.0 = Development|ARM + {GF11038F0-88E5-11E7-BA7C-E36C7490591B}.Development|x64.ActiveCfg = Development|x64 + {GF11038F0-88E5-11E7-BA7C-E36C7490591B}.Development|x64.Build.0 = Development|x64 + {GF11038F0-88E5-11E7-BA7C-E36C7490591B}.Development|x86.ActiveCfg = Development|x86 + {GF11038F0-88E5-11E7-BA7C-E36C7490591B}.Development|x86.Build.0 = Development|x86 + {GF11038F0-88E5-11E7-BA7C-E36C7490591B}.Release|ARM.ActiveCfg = Release|ARM + {GF11038F0-88E5-11E7-BA7C-E36C7490591B}.Release|ARM.Build.0 = Release|ARM + {GF11038F0-88E5-11E7-BA7C-E36C7490591B}.Release|x64.ActiveCfg = Release|x64 + {GF11038F0-88E5-11E7-BA7C-E36C7490591B}.Release|x64.Build.0 = Release|x64 + {GF11038F0-88E5-11E7-BA7C-E36C7490591B}.Release|x86.ActiveCfg = Release|x86 + {GF11038F0-88E5-11E7-BA7C-E36C7490591B}.Release|x86.Build.0 = Release|x86 {C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Debug|ARM.ActiveCfg = Debug|ARM {C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Debug|ARM.Build.0 = Debug|ARM {C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Debug|x64.ActiveCfg = Debug|x64 diff --git a/windows/RNDocumentPicker/NginxMimeTypes.cs b/windows/RNDocumentPicker/NginxMimeTypes.cs deleted file mode 100644 index 4305b76..0000000 --- a/windows/RNDocumentPicker/NginxMimeTypes.cs +++ /dev/null @@ -1,126 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace RNDocumentPicker -{ - static class NginxMimeTypes - { - public static Dictionary> MimeTypeDictionary = new Dictionary> { - {"application/atom+xml", new List{"atom"} }, - {"application/font-woff", new List{"woff"} }, - {"application/java-archive", new List{"jar","war","ear"} }, - {"application/javascript", new List{"js"} }, - {"application/json", new List{"json"} }, - {"application/mac-binhex40", new List{"hqx"} }, - {"application/msword", new List{"doc"} }, - {"application/octet-stream", new List{"bin","exe","dll","deb","dmg","iso","img","msi","msp","msm"} }, - {"application/pdf", new List{"pdf"} }, - {"application/postscript", new List{"ps","eps","ai"} }, - {"application/rss+xml", new List{"rss"} }, - {"application/rtf", new List{"rtf"} }, - {"application/vnd.apple.mpegurl", new List{"m3u8"} }, - {"application/vnd.google-earth.kml+xml", new List{"kml"} }, - {"application/vnd.google-earth.kmz", new List{"kmz"} }, - {"application/vnd.ms-excel", new List{"xls"} }, - {"application/vnd.ms-fontobject", new List{"eot"} }, - {"application/vnd.ms-powerpoint", new List{"ppt"} }, - {"application/vnd.oasis.opendocument.graphics", new List{"odg"} }, - {"application/vnd.oasis.opendocument.presentation", new List{"odp"} }, - {"application/vnd.oasis.opendocument.spreadsheet", new List{"ods"} }, - {"application/vnd.oasis.opendocument.text", new List{"odt"} }, - {"application/vnd.openxmlformats-officedocument.presentationml.presentation", new List{"pptx"} }, - {"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", new List{"xlsx"} }, - {"application/vnd.openxmlformats-officedocument.wordprocessingml.document", new List{"docx"} }, - {"application/vnd.wap.wmlc", new List{"wmlc"} }, - {"application/x-7z-compressed", new List{"7z"} }, - {"application/x-cocoa", new List{"cco"} }, - {"application/x-java-archive-diff", new List{"jardiff"} }, - {"application/x-java-jnlp-file", new List{"jnlp"} }, - {"application/x-makeself", new List{"run"} }, - {"application/x-perl", new List{"pl","pm"} }, - {"application/x-pilot", new List{"prc","pdb"} }, - {"application/x-rar-compressed", new List{"rar"} }, - {"application/x-redhat-package-manager", new List{"rpm"} }, - {"application/x-sea", new List{"sea"} }, - {"application/x-shockwave-flash", new List{"swf"} }, - {"application/x-stuffit", new List{"sit"} }, - {"application/x-tcl", new List{"tcl","tk"} }, - {"application/x-x509-ca-cert", new List{"der","pem","crt"} }, - {"application/x-xpinstall", new List{"xpi"} }, - {"application/xhtml+xml", new List{"xhtml"} }, - {"application/xspf+xml", new List{"xspf"} }, - {"application/zip", new List{"zip"} }, - {"audio/midi", new List{"mid","midi","kar"} }, - {"audio/mpeg", new List{"mp3"} }, - {"audio/ogg", new List{"ogg"} }, - {"audio/x-m4a", new List{"m4a"} }, - {"audio/x-realaudio", new List{"ra"} }, - {"image/gif", new List{"gif"} }, - {"image/jpeg", new List{"jpeg","jpg"} }, - {"image/png", new List{"png"} }, - {"image/svg+xml", new List{"svg","svgz"} }, - {"image/tiff", new List{"tif","tiff"} }, - {"image/vnd.wap.wbmp", new List{"wbmp"} }, - {"image/webp", new List{"webp"} }, - {"image/x-icon", new List{"ico"} }, - {"image/x-jng", new List{"jng"} }, - {"image/x-ms-bmp", new List{"bmp"} }, - {"text/css", new List{"css"} }, - {"text/html", new List{"html","htm","shtml"} }, - {"text/mathml", new List{"mml"} }, - {"text/plain", new List{"txt"} }, - {"text/vnd.sun.j2me.app-descriptor", new List{"jad"} }, - {"text/vnd.wap.wml", new List{"wml"} }, - {"text/x-component", new List{"htc"} }, - {"text/xml", new List{"xml"} }, - {"video/3gpp", new List{"3gpp","3gp"} }, - {"video/mp2t", new List{"ts"} }, - {"video/mp4", new List{"mp4"} }, - {"video/mpeg", new List{"mpeg","mpg"} }, - {"video/quicktime", new List{"mov"} }, - {"video/webm", new List{"webm"} }, - {"video/x-flv", new List{"flv"} }, - {"video/x-m4v", new List{"m4v"} }, - {"video/x-mng", new List{"mng"} }, - {"video/x-ms-asf", new List{"asx","asf"} }, - {"video/x-ms-wmv", new List{"wmv"} }, - {"video/x-msvideo", new List{"avi"} } - }; - - /// - /// Returns the extensions of matching mime type - /// - /// - /// - private static List FindExtensionsByMimeType(string MimeType) - { - - return MimeTypeDictionary.Where(mt => mt.Key.ToLowerInvariant().Contains(MimeType.ToLowerInvariant())).Select(mt => mt.Value).SelectMany(x => x).Select(x => "." + x).ToList(); - - } - - /// - /// Returns the Extensions that matches the MimeType. If no match is found an error is thrown. - /// - /// - /// - public static List GetExtensions(List MimeTypes) - { - List result = new List(); - foreach (string MimeType in MimeTypes) { - if (MimeType != "*/*") - { - result = result.Union(FindExtensionsByMimeType(MimeType.Replace("*", string.Empty))).ToList(); - } - else { - result = new List() { "*" }; - break; - } - } - return result; - } - } -} diff --git a/windows/RNDocumentPicker/RCTDocumentPickerModule.cs b/windows/RNDocumentPicker/RCTDocumentPickerModule.cs index 4b1d2df..36a6e2f 100644 --- a/windows/RNDocumentPicker/RCTDocumentPickerModule.cs +++ b/windows/RNDocumentPicker/RCTDocumentPickerModule.cs @@ -76,16 +76,19 @@ namespace RNDocumentPicker openPicker.ViewMode = PickerViewMode.Thumbnail; openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; // Get file type array options - var mimeTypes = options.Value(OPTION_TYPE); + var fileTypeArray = options.Value(OPTION_TYPE); // Init file type filter - if (mimeTypes != null && mimeTypes.Count > 0) + if (fileTypeArray != null && fileTypeArray.Count > 0) { - List types = NginxMimeTypes.GetExtensions(mimeTypes.ToObject>()); - foreach (String type in types) + foreach (String typeString in fileTypeArray) { - if (Regex.Match(type, "(^[.]+[A-Za-z0-9]*$)|(^[*]$)").Success) + List types = typeString.Split(' ').ToList(); + foreach (String type in types) { - openPicker.FileTypeFilter.Add(type); + if (Regex.Match(type, "(^[.]+[A-Za-z0-9]*$)|(^[*]$)").Success) + { + openPicker.FileTypeFilter.Add(type); + } } } } diff --git a/windows/RNDocumentPicker/RNDocumentPicker.csproj b/windows/RNDocumentPicker/RNDocumentPicker.csproj index b04d85f..9d14dbd 100644 --- a/windows/RNDocumentPicker/RNDocumentPicker.csproj +++ b/windows/RNDocumentPicker/RNDocumentPicker.csproj @@ -128,7 +128,6 @@ -