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