Ryan Linton před 7 roky
rodič
revize
adc46b7fd7

+ 2
- 2
README.md Zobrazit soubor

@@ -95,9 +95,9 @@ react-native link react-native-view-shot
95 95
 
96 96
 #### Windows
97 97
 
98
-1. In Visual Studio, in the solution explorer, right click on your project solution then select `Add` ➜ `ExisitingProject`
98
+1. In Visual Studio, in the solution explorer, right click on your solution then select `Add` ➜ `ExisitingProject`
99 99
 2. Go to `node_modules` ➜ `react-native-view-shot` and add `RNViewShot.csproj` (UWP) or optionally `RNViewShot.Net46.csproj` (WPF)
100
-3. In Visual Studio, in the solution explorer, right click on your project then select `Add` ➜ `Reference`
100
+3. In Visual Studio, in the solution explorer, right click on your Application project then select `Add` ➜ `Reference`
101 101
 4. Under the projects tab select `RNViewShot` (UWP) or `RNViewShot.Net46` (WPF)
102 102
 
103 103
 

+ 2
- 1
windows/RNViewShot.Net46/RNViewShotModule.cs Zobrazit soubor

@@ -51,7 +51,8 @@ namespace RNViewShot
51 51
             }
52 52
 
53 53
             UIManagerModule uiManager = this._reactContext.GetNativeModule<UIManagerModule>();
54
-            uiManager.AddUIBlock(new ViewShot(tag, format, quality, width, height, path, result, promise));
54
+            var viewShot = new ViewShot(tag, format, quality, width, height, path, result, promise);
55
+            uiManager.AddUIBlock(viewShot);
55 56
         }
56 57
     }
57 58
 }

+ 2
- 1
windows/RNViewShot.Net46/ViewShot.cs Zobrazit soubor

@@ -1,6 +1,7 @@
1 1
 using ReactNative.Bridge;
2 2
 using ReactNative.UIManager;
3 3
 using System;
4
+using System.Diagnostics;
4 5
 using System.IO;
5 6
 using System.Windows;
6 7
 using System.Windows.Media;
@@ -87,7 +88,7 @@ namespace RNViewShot
87 88
             }
88 89
             catch (Exception ex)
89 90
             {
90
-                Console.WriteLine(ex.ToString());
91
+                Debug.WriteLine(ex.ToString());
91 92
                 promise.Reject(ErrorUnableToSnapshot, "Failed to capture view snapshot");
92 93
             }
93 94
         }

+ 2
- 1
windows/RNViewShot/RNViewShotModule.cs Zobrazit soubor

@@ -51,7 +51,8 @@ namespace RNViewShot
51 51
             }
52 52
 
53 53
             UIManagerModule uiManager = this._reactContext.GetNativeModule<UIManagerModule>();
54
-            uiManager.AddUIBlock(new ViewShot(tag, format, quality, width, height, path, result, promise));
54
+            var viewShot = new ViewShot(tag, format, quality, width, height, path, result, promise);
55
+            uiManager.AddUIBlock(viewShot);
55 56
         }
56 57
     }
57 58
 }

+ 11
- 19
windows/RNViewShot/ViewShot.cs Zobrazit soubor

@@ -1,6 +1,7 @@
1 1
 using ReactNative.Bridge;
2 2
 using ReactNative.UIManager;
3 3
 using System;
4
+using System.Diagnostics;
4 5
 using System.IO;
5 6
 using System.Runtime.InteropServices.WindowsRuntime;
6 7
 using System.Threading.Tasks;
@@ -9,7 +10,6 @@ using Windows.Graphics.Imaging;
9 10
 using Windows.Storage;
10 11
 using Windows.Storage.Streams;
11 12
 using Windows.UI.Xaml;
12
-using Windows.UI.Xaml.Media;
13 13
 using Windows.UI.Xaml.Media.Imaging;
14 14
 
15 15
 namespace RNViewShot
@@ -59,10 +59,10 @@ namespace RNViewShot
59 59
             {
60 60
                 if ("file" == result)
61 61
                 {
62
-                    using (InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream())
62
+                    using (var ras = new InMemoryRandomAccessStream())
63 63
                     {
64 64
                         await CaptureView(view, ras);
65
-                        StorageFile file = await GetStorageFile();
65
+                        var file = await GetStorageFile();
66 66
                         using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite))
67 67
                         {
68 68
                             await RandomAccessStream.CopyAndCloseAsync(ras.GetInputStreamAt(0), fileStream.GetOutputStreamAt(0));
@@ -72,10 +72,10 @@ namespace RNViewShot
72 72
                 }
73 73
                 else if ("base64" == result)
74 74
                 {
75
-                    using (InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream())
75
+                    using (var ras = new InMemoryRandomAccessStream())
76 76
                     {
77 77
                         await CaptureView(view, ras);
78
-                        byte[] imageBytes = new byte[ras.Size];
78
+                        var imageBytes = new byte[ras.Size];
79 79
                         await ras.AsStream().ReadAsync(imageBytes, 0, imageBytes.Length);
80 80
                         string data = Convert.ToBase64String(imageBytes);
81 81
                         promise.Resolve(data);
@@ -83,10 +83,10 @@ namespace RNViewShot
83 83
                 }
84 84
                 else if ("data-uri" == result)
85 85
                 {
86
-                    using (InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream())
86
+                    using (var ras = new InMemoryRandomAccessStream())
87 87
                     {
88 88
                         await CaptureView(view, ras);
89
-                        byte[] imageBytes = new byte[ras.Size];
89
+                        var imageBytes = new byte[ras.Size];
90 90
                         await ras.AsStream().ReadAsync(imageBytes, 0, imageBytes.Length);
91 91
                         string data = Convert.ToBase64String(imageBytes);
92 92
                         data = "data:image/" + extension + ";base64," + data;
@@ -100,7 +100,7 @@ namespace RNViewShot
100 100
             }
101 101
             catch (Exception ex)
102 102
             {
103
-                Console.WriteLine(ex.ToString());
103
+                Debug.WriteLine(ex.ToString());
104 104
                 promise.Reject(ErrorUnableToSnapshot, "Failed to capture view snapshot");
105 105
             }
106 106
         }
@@ -162,17 +162,9 @@ namespace RNViewShot
162 162
 
163 163
         private async Task<StorageFile> GetStorageFile()
164 164
         {
165
-            StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
166
-            if (string.IsNullOrEmpty(path))
167
-            {
168
-                string fileName = Guid.NewGuid().ToString();
169
-                fileName = Path.ChangeExtension(fileName, extension);
170
-                return await storageFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
171
-            }
172
-            else
173
-            {
174
-                return await storageFolder.CreateFileAsync(path, CreationCollisionOption.ReplaceExisting);
175
-            }
165
+            var storageFolder = ApplicationData.Current.LocalFolder;
166
+            var fileName = string.IsNullOrEmpty(path) ? path : Path.ChangeExtension(Guid.NewGuid().ToString(), extension);                
167
+            return await storageFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
176 168
         }
177 169
     }
178 170
 }