Change request applied:

* Removed mime type - extensions transform
* index.js refactoring applied
This commit is contained in:
Genc, Alper Numan 2017-10-23 08:30:11 +03:00
parent cadc0a0f63
commit 2d27f77718
5 changed files with 61 additions and 160 deletions

View File

@ -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 || {};

View File

@ -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

View File

@ -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<string, List<string>> MimeTypeDictionary = new Dictionary<string, List<string>> {
{"application/atom+xml", new List<string>{"atom"} },
{"application/font-woff", new List<string>{"woff"} },
{"application/java-archive", new List<string>{"jar","war","ear"} },
{"application/javascript", new List<string>{"js"} },
{"application/json", new List<string>{"json"} },
{"application/mac-binhex40", new List<string>{"hqx"} },
{"application/msword", new List<string>{"doc"} },
{"application/octet-stream", new List<string>{"bin","exe","dll","deb","dmg","iso","img","msi","msp","msm"} },
{"application/pdf", new List<string>{"pdf"} },
{"application/postscript", new List<string>{"ps","eps","ai"} },
{"application/rss+xml", new List<string>{"rss"} },
{"application/rtf", new List<string>{"rtf"} },
{"application/vnd.apple.mpegurl", new List<string>{"m3u8"} },
{"application/vnd.google-earth.kml+xml", new List<string>{"kml"} },
{"application/vnd.google-earth.kmz", new List<string>{"kmz"} },
{"application/vnd.ms-excel", new List<string>{"xls"} },
{"application/vnd.ms-fontobject", new List<string>{"eot"} },
{"application/vnd.ms-powerpoint", new List<string>{"ppt"} },
{"application/vnd.oasis.opendocument.graphics", new List<string>{"odg"} },
{"application/vnd.oasis.opendocument.presentation", new List<string>{"odp"} },
{"application/vnd.oasis.opendocument.spreadsheet", new List<string>{"ods"} },
{"application/vnd.oasis.opendocument.text", new List<string>{"odt"} },
{"application/vnd.openxmlformats-officedocument.presentationml.presentation", new List<string>{"pptx"} },
{"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", new List<string>{"xlsx"} },
{"application/vnd.openxmlformats-officedocument.wordprocessingml.document", new List<string>{"docx"} },
{"application/vnd.wap.wmlc", new List<string>{"wmlc"} },
{"application/x-7z-compressed", new List<string>{"7z"} },
{"application/x-cocoa", new List<string>{"cco"} },
{"application/x-java-archive-diff", new List<string>{"jardiff"} },
{"application/x-java-jnlp-file", new List<string>{"jnlp"} },
{"application/x-makeself", new List<string>{"run"} },
{"application/x-perl", new List<string>{"pl","pm"} },
{"application/x-pilot", new List<string>{"prc","pdb"} },
{"application/x-rar-compressed", new List<string>{"rar"} },
{"application/x-redhat-package-manager", new List<string>{"rpm"} },
{"application/x-sea", new List<string>{"sea"} },
{"application/x-shockwave-flash", new List<string>{"swf"} },
{"application/x-stuffit", new List<string>{"sit"} },
{"application/x-tcl", new List<string>{"tcl","tk"} },
{"application/x-x509-ca-cert", new List<string>{"der","pem","crt"} },
{"application/x-xpinstall", new List<string>{"xpi"} },
{"application/xhtml+xml", new List<string>{"xhtml"} },
{"application/xspf+xml", new List<string>{"xspf"} },
{"application/zip", new List<string>{"zip"} },
{"audio/midi", new List<string>{"mid","midi","kar"} },
{"audio/mpeg", new List<string>{"mp3"} },
{"audio/ogg", new List<string>{"ogg"} },
{"audio/x-m4a", new List<string>{"m4a"} },
{"audio/x-realaudio", new List<string>{"ra"} },
{"image/gif", new List<string>{"gif"} },
{"image/jpeg", new List<string>{"jpeg","jpg"} },
{"image/png", new List<string>{"png"} },
{"image/svg+xml", new List<string>{"svg","svgz"} },
{"image/tiff", new List<string>{"tif","tiff"} },
{"image/vnd.wap.wbmp", new List<string>{"wbmp"} },
{"image/webp", new List<string>{"webp"} },
{"image/x-icon", new List<string>{"ico"} },
{"image/x-jng", new List<string>{"jng"} },
{"image/x-ms-bmp", new List<string>{"bmp"} },
{"text/css", new List<string>{"css"} },
{"text/html", new List<string>{"html","htm","shtml"} },
{"text/mathml", new List<string>{"mml"} },
{"text/plain", new List<string>{"txt"} },
{"text/vnd.sun.j2me.app-descriptor", new List<string>{"jad"} },
{"text/vnd.wap.wml", new List<string>{"wml"} },
{"text/x-component", new List<string>{"htc"} },
{"text/xml", new List<string>{"xml"} },
{"video/3gpp", new List<string>{"3gpp","3gp"} },
{"video/mp2t", new List<string>{"ts"} },
{"video/mp4", new List<string>{"mp4"} },
{"video/mpeg", new List<string>{"mpeg","mpg"} },
{"video/quicktime", new List<string>{"mov"} },
{"video/webm", new List<string>{"webm"} },
{"video/x-flv", new List<string>{"flv"} },
{"video/x-m4v", new List<string>{"m4v"} },
{"video/x-mng", new List<string>{"mng"} },
{"video/x-ms-asf", new List<string>{"asx","asf"} },
{"video/x-ms-wmv", new List<string>{"wmv"} },
{"video/x-msvideo", new List<string>{"avi"} }
};
/// <summary>
/// Returns the extensions of matching mime type
/// </summary>
/// <param name="MimeType"></param>
/// <returns></returns>
private static List<string> FindExtensionsByMimeType(string MimeType)
{
return MimeTypeDictionary.Where(mt => mt.Key.ToLowerInvariant().Contains(MimeType.ToLowerInvariant())).Select(mt => mt.Value).SelectMany(x => x).Select(x => "." + x).ToList();
}
/// <summary>
/// Returns the Extensions that matches the MimeType. If no match is found an error is thrown.
/// </summary>
/// <param name="MimeType"></param>
/// <returns></returns>
public static List<string> GetExtensions(List<string> MimeTypes)
{
List<string> result = new List<string>();
foreach (string MimeType in MimeTypes) {
if (MimeType != "*/*")
{
result = result.Union(FindExtensionsByMimeType(MimeType.Replace("*", string.Empty))).ToList();
}
else {
result = new List<string>() { "*" };
break;
}
}
return result;
}
}
}

View File

@ -76,16 +76,19 @@ namespace RNDocumentPicker
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
// Get file type array options
var mimeTypes = options.Value<JArray>(OPTION_TYPE);
var fileTypeArray = options.Value<JArray>(OPTION_TYPE);
// Init file type filter
if (mimeTypes != null && mimeTypes.Count > 0)
if (fileTypeArray != null && fileTypeArray.Count > 0)
{
List<String> types = NginxMimeTypes.GetExtensions(mimeTypes.ToObject<List<string>>());
foreach (String type in types)
foreach (String typeString in fileTypeArray)
{
if (Regex.Match(type, "(^[.]+[A-Za-z0-9]*$)|(^[*]$)").Success)
List<String> 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);
}
}
}
}

View File

@ -128,7 +128,6 @@
<None Include="project.json" />
</ItemGroup>
<ItemGroup>
<Compile Include="NginxMimeTypes.cs" />
<Compile Include="RCTDocumentPickerModule.cs" />
<Compile Include="RNDocumentPickerPackage.cs" />
<EmbeddedResource Include="Properties\RNDocumentPicker.rd.xml">