react-native-windows 0.72.1 → 0.72.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Libraries/Core/ReactNativeVersion.js +1 -1
- package/Libraries/Network/RCTNetworking.windows.js +10 -16
- package/Microsoft.ReactNative/Fabric/ImageRequest.cpp +11 -14
- package/Microsoft.ReactNative/Fabric/WindowsImageManager.cpp +1 -1
- package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +1 -3
- package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj.filters +0 -7
- package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +11 -10
- package/Microsoft.ReactNative.Cxx/JSValueReader.h +1 -1
- package/Microsoft.ReactNative.Cxx/JSValueWriter.h +1 -1
- package/Microsoft.ReactNative.Cxx/ModuleRegistration.h +22 -0
- package/Microsoft.ReactNative.Cxx/NativeModules.h +5 -0
- package/Microsoft.ReactNative.Cxx/StructInfo.h +4 -4
- package/Microsoft.ReactNative.Managed/packages.lock.json +2 -71
- package/PropertySheets/Generated/PackageVersion.g.props +3 -3
- package/PropertySheets/React.Cpp.props +2 -3
- package/Shared/BaseFileReaderResource.cpp +95 -0
- package/Shared/BaseFileReaderResource.h +41 -0
- package/Shared/CreateModules.h +27 -5
- package/Shared/IFileReaderResource.h +36 -0
- package/Shared/Modules/BlobModule.cpp +93 -297
- package/Shared/Modules/BlobModule.h +25 -87
- package/Shared/Modules/CxxModuleUtilities.cpp +32 -0
- package/Shared/Modules/CxxModuleUtilities.h +17 -0
- package/Shared/Modules/FileReaderModule.cpp +118 -51
- package/Shared/Modules/FileReaderModule.h +27 -1
- package/Shared/Modules/HttpModule.cpp +133 -9
- package/Shared/Modules/HttpModule.h +33 -0
- package/Shared/Modules/IRequestBodyHandler.h +6 -4
- package/Shared/Modules/IResponseHandler.h +3 -3
- package/Shared/Modules/IUriHandler.h +3 -3
- package/Shared/Modules/IWebSocketModuleContentHandler.h +6 -4
- package/Shared/Modules/WebSocketModule.cpp +190 -7
- package/Shared/Modules/WebSocketTurboModule.h +52 -0
- package/Shared/Networking/DefaultBlobResource.cpp +323 -0
- package/Shared/Networking/DefaultBlobResource.h +133 -0
- package/Shared/Networking/IBlobResource.h +56 -0
- package/Shared/Networking/IHttpResource.h +6 -5
- package/Shared/Networking/WinRTHttpResource.cpp +40 -32
- package/Shared/Networking/WinRTHttpResource.h +4 -3
- package/Shared/Networking/WinRTTypes.h +3 -3
- package/Shared/Shared.vcxitems +8 -1
- package/Shared/Shared.vcxitems.filters +24 -3
- package/package.json +13 -13
- package/types/experimental.d.ts +101 -0
- package/types/index.d.ts +216 -0
- package/types/modules/BatchedBridge.d.ts +32 -0
- package/types/modules/Codegen.d.ts +74 -0
- package/types/modules/Devtools.d.ts +31 -0
- package/types/modules/LaunchScreen.d.ts +18 -0
- package/types/modules/globals.d.ts +579 -0
- package/types/private/TimerMixin.d.ts +19 -0
- package/types/private/Utilities.d.ts +10 -0
- package/types/public/DeprecatedPropertiesAlias.d.ts +185 -0
- package/types/public/Insets.d.ts +15 -0
- package/types/public/ReactNativeRenderer.d.ts +144 -0
- package/types/public/ReactNativeTypes.d.ts +143 -0
- package/Microsoft.ReactNative/Base/CoreNativeModules.cpp +0 -44
- package/Microsoft.ReactNative/Base/CoreNativeModules.h +0 -30
- /package/Shared/{Modules/IBlobPersistor.h → IBlobPersistor.h} +0 -0
|
@@ -3,10 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
#pragma once
|
|
5
5
|
|
|
6
|
-
#include <
|
|
7
|
-
|
|
8
|
-
#include <
|
|
9
|
-
#include <Modules/IWebSocketModuleContentHandler.h>
|
|
6
|
+
#include <NativeBlobModuleSpec.g.h>
|
|
7
|
+
|
|
8
|
+
#include <Networking/IBlobResource.h>
|
|
10
9
|
|
|
11
10
|
// React Native
|
|
12
11
|
#include <cxxreact/CxxModule.h>
|
|
@@ -15,91 +14,45 @@
|
|
|
15
14
|
#include <winrt/base.h>
|
|
16
15
|
|
|
17
16
|
// Standard Library
|
|
18
|
-
#include <mutex>
|
|
19
17
|
#include <string>
|
|
20
|
-
#include <unordered_map>
|
|
21
|
-
#include <unordered_set>
|
|
22
18
|
#include <vector>
|
|
23
19
|
|
|
24
20
|
namespace Microsoft::React {
|
|
25
21
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
public:
|
|
31
|
-
#pragma region IBlobPersistor
|
|
32
|
-
|
|
33
|
-
winrt::array_view<uint8_t const> ResolveMessage(std::string &&blobId, int64_t offset, int64_t size) override;
|
|
34
|
-
|
|
35
|
-
void RemoveMessage(std::string &&blobId) noexcept override;
|
|
36
|
-
|
|
37
|
-
void StoreMessage(std::vector<uint8_t> &&message, std::string &&blobId) noexcept override;
|
|
38
|
-
|
|
39
|
-
std::string StoreMessage(std::vector<uint8_t> &&message) noexcept override;
|
|
40
|
-
|
|
41
|
-
#pragma endregion IBlobPersistor
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
class BlobWebSocketModuleContentHandler final : public IWebSocketModuleContentHandler {
|
|
45
|
-
std::unordered_set<int64_t> m_socketIds;
|
|
46
|
-
std::mutex m_mutex;
|
|
47
|
-
std::shared_ptr<IBlobPersistor> m_blobPersistor;
|
|
48
|
-
|
|
49
|
-
public:
|
|
50
|
-
BlobWebSocketModuleContentHandler(std::shared_ptr<IBlobPersistor> blobPersistor) noexcept;
|
|
51
|
-
|
|
52
|
-
#pragma region IWebSocketModuleContentHandler
|
|
53
|
-
|
|
54
|
-
void ProcessMessage(std::string &&message, folly::dynamic ¶ms) override;
|
|
55
|
-
|
|
56
|
-
void ProcessMessage(std::vector<uint8_t> &&message, folly::dynamic ¶ms) override;
|
|
57
|
-
|
|
58
|
-
#pragma endregion IWebSocketModuleContentHandler
|
|
59
|
-
|
|
60
|
-
void Register(int64_t socketID) noexcept;
|
|
22
|
+
REACT_MODULE(BlobTurboModule, L"BlobModule")
|
|
23
|
+
struct BlobTurboModule {
|
|
24
|
+
using ModuleSpec = ReactNativeSpecs::BlobModuleSpec;
|
|
61
25
|
|
|
62
|
-
|
|
63
|
-
|
|
26
|
+
REACT_INIT(Initialize)
|
|
27
|
+
void Initialize(winrt::Microsoft::ReactNative::ReactContext const &reactContext) noexcept;
|
|
64
28
|
|
|
65
|
-
|
|
66
|
-
|
|
29
|
+
REACT_GET_CONSTANTS(GetConstants)
|
|
30
|
+
ReactNativeSpecs::BlobModuleSpec_Constants GetConstants() noexcept;
|
|
67
31
|
|
|
68
|
-
|
|
69
|
-
|
|
32
|
+
REACT_METHOD(AddNetworkingHandler, L"addNetworkingHandler")
|
|
33
|
+
void AddNetworkingHandler() noexcept;
|
|
70
34
|
|
|
71
|
-
|
|
35
|
+
REACT_METHOD(AddWebSocketHandler, L"addWebSocketHandler")
|
|
36
|
+
void AddWebSocketHandler(double id) noexcept;
|
|
72
37
|
|
|
73
|
-
|
|
38
|
+
REACT_METHOD(RemoveWebSocketHandler, L"removeWebSocketHandler")
|
|
39
|
+
void RemoveWebSocketHandler(double id) noexcept;
|
|
74
40
|
|
|
75
|
-
|
|
41
|
+
REACT_METHOD(SendOverSocket, L"sendOverSocket")
|
|
42
|
+
void SendOverSocket(winrt::Microsoft::ReactNative::JSValue &&blob, double socketID) noexcept;
|
|
76
43
|
|
|
77
|
-
|
|
78
|
-
|
|
44
|
+
REACT_METHOD(CreateFromParts, L"createFromParts")
|
|
45
|
+
void CreateFromParts(std::vector<winrt::Microsoft::ReactNative::JSValue> &&parts, std::string &&withId) noexcept;
|
|
79
46
|
|
|
80
|
-
|
|
81
|
-
std::
|
|
82
|
-
|
|
83
|
-
public:
|
|
84
|
-
BlobModuleResponseHandler(std::shared_ptr<IBlobPersistor> blobPersistor) noexcept;
|
|
47
|
+
REACT_METHOD(Release, L"release")
|
|
48
|
+
void Release(std::string &&blobId) noexcept;
|
|
85
49
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
bool Supports(std::string &responseType) override;
|
|
89
|
-
|
|
90
|
-
folly::dynamic ToResponseData(std::vector<uint8_t> &&content) override;
|
|
91
|
-
|
|
92
|
-
#pragma endregion IResponseHandler
|
|
50
|
+
private:
|
|
51
|
+
std::shared_ptr<Networking::IBlobResource> m_resource;
|
|
93
52
|
};
|
|
94
53
|
|
|
95
54
|
class BlobModule : public facebook::xplat::module::CxxModule {
|
|
96
|
-
std::shared_ptr<
|
|
97
|
-
std::shared_ptr<BlobWebSocketModuleContentHandler> m_contentHandler;
|
|
98
|
-
std::shared_ptr<BlobModuleRequestBodyHandler> m_requestBodyHandler;
|
|
99
|
-
std::shared_ptr<BlobModuleResponseHandler> m_responseHandler;
|
|
100
|
-
|
|
101
|
-
// Property bag high level reference.
|
|
102
|
-
winrt::Windows::Foundation::IInspectable m_inspectableProperties;
|
|
55
|
+
std::shared_ptr<Networking::IBlobResource> m_resource;
|
|
103
56
|
|
|
104
57
|
public:
|
|
105
58
|
enum class MethodId {
|
|
@@ -114,15 +67,6 @@ class BlobModule : public facebook::xplat::module::CxxModule {
|
|
|
114
67
|
|
|
115
68
|
BlobModule(winrt::Windows::Foundation::IInspectable const &inspectableProperties) noexcept;
|
|
116
69
|
|
|
117
|
-
~BlobModule() noexcept override;
|
|
118
|
-
|
|
119
|
-
struct SharedState {
|
|
120
|
-
/// <summary>
|
|
121
|
-
/// Keeps a raw reference to the module object to lazily retrieve the React Instance as needed.
|
|
122
|
-
/// </summary>
|
|
123
|
-
CxxModule *Module{nullptr};
|
|
124
|
-
};
|
|
125
|
-
|
|
126
70
|
#pragma region CxxModule
|
|
127
71
|
|
|
128
72
|
/// <summary>
|
|
@@ -142,12 +86,6 @@ class BlobModule : public facebook::xplat::module::CxxModule {
|
|
|
142
86
|
std::vector<Method> getMethods() override;
|
|
143
87
|
|
|
144
88
|
#pragma endregion CxxModule
|
|
145
|
-
|
|
146
|
-
private:
|
|
147
|
-
/// <summary>
|
|
148
|
-
/// Keeps members that can be accessed threads other than this module's owner accessible.
|
|
149
|
-
/// </summary>
|
|
150
|
-
std::shared_ptr<SharedState> m_sharedState;
|
|
151
89
|
};
|
|
152
90
|
|
|
153
91
|
} // namespace Microsoft::React
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
4
|
#include "CxxModuleUtilities.h"
|
|
5
|
+
#include <DynamicReader.h>
|
|
6
|
+
#include <DynamicWriter.h>
|
|
7
|
+
|
|
8
|
+
namespace msrn = winrt::Microsoft::ReactNative;
|
|
5
9
|
|
|
6
10
|
using facebook::react::Instance;
|
|
7
11
|
using folly::dynamic;
|
|
@@ -16,4 +20,32 @@ void SendEvent(weak_ptr<Instance> weakReactInstance, string &&eventName, dynamic
|
|
|
16
20
|
}
|
|
17
21
|
}
|
|
18
22
|
|
|
23
|
+
void SendEvent(
|
|
24
|
+
msrn::ReactContext const &reactContext,
|
|
25
|
+
std::wstring_view &&eventName,
|
|
26
|
+
msrn::JSValueObject &&args) noexcept {
|
|
27
|
+
reactContext.EmitJSEvent(L"RCTDeviceEventEmitter", std::move(eventName), std::move(args));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
void SendEvent(
|
|
31
|
+
msrn::ReactContext const &reactContext,
|
|
32
|
+
std::wstring_view &&eventName,
|
|
33
|
+
msrn::JSValueArray &&args) noexcept {
|
|
34
|
+
reactContext.EmitJSEvent(L"RCTDeviceEventEmitter", std::move(eventName), std::move(args));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
msrn::JSValue ToJSValue(dynamic &value) noexcept {
|
|
38
|
+
auto reader = winrt::make<msrn::DynamicReader>(value);
|
|
39
|
+
auto result = msrn::JSValue::ReadFrom(reader);
|
|
40
|
+
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
dynamic ToDynamic(const msrn::JSValue &value) noexcept {
|
|
45
|
+
auto argWriter = msrn::MakeJSValueArgWriter(value);
|
|
46
|
+
auto result = msrn::DynamicWriter::ToDynamic(argWriter)[0];
|
|
47
|
+
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
|
|
19
51
|
} // namespace Microsoft::React::Modules
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
// React Native
|
|
10
10
|
#include <cxxreact/Instance.h>
|
|
11
11
|
|
|
12
|
+
// React Native Windows
|
|
13
|
+
#include <ReactContext.h>
|
|
14
|
+
|
|
12
15
|
// Standard Library
|
|
13
16
|
#include <memory>
|
|
14
17
|
#include <string>
|
|
@@ -20,4 +23,18 @@ void SendEvent(
|
|
|
20
23
|
std::string &&eventName,
|
|
21
24
|
folly::dynamic &&args);
|
|
22
25
|
|
|
26
|
+
void SendEvent(
|
|
27
|
+
winrt::Microsoft::ReactNative::ReactContext const &reactContext,
|
|
28
|
+
std::wstring_view &&eventName,
|
|
29
|
+
winrt::Microsoft::ReactNative::JSValueObject &&args) noexcept;
|
|
30
|
+
|
|
31
|
+
void SendEvent(
|
|
32
|
+
winrt::Microsoft::ReactNative::ReactContext const &reactContext,
|
|
33
|
+
std::wstring_view &&eventName,
|
|
34
|
+
winrt::Microsoft::ReactNative::JSValueArray &&args) noexcept;
|
|
35
|
+
|
|
36
|
+
winrt::Microsoft::ReactNative::JSValue ToJSValue(folly::dynamic &value) noexcept;
|
|
37
|
+
|
|
38
|
+
folly::dynamic ToDynamic(const winrt::Microsoft::ReactNative::JSValue &value) noexcept;
|
|
39
|
+
|
|
23
40
|
} // namespace Microsoft::React::Modules
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
#include "FileReaderModule.h"
|
|
5
5
|
|
|
6
|
+
#include <CreateModules.h>
|
|
6
7
|
#include <ReactPropertyBag.h>
|
|
7
8
|
#include <sstream>
|
|
8
9
|
|
|
@@ -19,17 +20,18 @@
|
|
|
19
20
|
|
|
20
21
|
using namespace facebook::xplat;
|
|
21
22
|
|
|
23
|
+
namespace msrn = winrt::Microsoft::ReactNative;
|
|
24
|
+
|
|
22
25
|
using folly::dynamic;
|
|
23
26
|
using std::string;
|
|
24
27
|
using std::weak_ptr;
|
|
25
|
-
using winrt::Microsoft::ReactNative::IReactPropertyBag;
|
|
26
|
-
using winrt::Microsoft::ReactNative::ReactNonAbiValue;
|
|
27
|
-
using winrt::Microsoft::ReactNative::ReactPropertyBag;
|
|
28
|
-
using winrt::Microsoft::ReactNative::ReactPropertyId;
|
|
29
28
|
using winrt::Windows::Foundation::IInspectable;
|
|
30
29
|
|
|
31
30
|
namespace {
|
|
32
|
-
constexpr char
|
|
31
|
+
constexpr char s_moduleName[] = "FileReaderModule";
|
|
32
|
+
constexpr wchar_t s_moduleNameW[] = L"FileReaderModule";
|
|
33
|
+
|
|
34
|
+
msrn::ReactModuleProvider s_moduleProvider = msrn::MakeTurboModuleProvider<Microsoft::React::FileReaderTurboModule>();
|
|
33
35
|
} // namespace
|
|
34
36
|
|
|
35
37
|
namespace Microsoft::React {
|
|
@@ -37,7 +39,7 @@ namespace Microsoft::React {
|
|
|
37
39
|
#pragma region FileReaderModule
|
|
38
40
|
|
|
39
41
|
FileReaderModule::FileReaderModule(weak_ptr<IBlobPersistor> weakBlobPersistor) noexcept
|
|
40
|
-
:
|
|
42
|
+
: m_resource{IFileReaderResource::Make(weakBlobPersistor)} {}
|
|
41
43
|
|
|
42
44
|
FileReaderModule::~FileReaderModule() noexcept /*override*/
|
|
43
45
|
{}
|
|
@@ -45,7 +47,7 @@ FileReaderModule::~FileReaderModule() noexcept /*override*/
|
|
|
45
47
|
#pragma region CxxModule
|
|
46
48
|
|
|
47
49
|
string FileReaderModule::getName() {
|
|
48
|
-
return
|
|
50
|
+
return s_moduleName;
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
std::map<string, dynamic> FileReaderModule::getConstants() {
|
|
@@ -61,41 +63,28 @@ std::vector<module::CxxModule::Method> FileReaderModule::getMethods() {
|
|
|
61
63
|
/// </param>
|
|
62
64
|
///
|
|
63
65
|
"readAsDataURL",
|
|
64
|
-
[
|
|
65
|
-
if (!blobPersistor) {
|
|
66
|
-
return reject({"Could not find Blob persistor"});
|
|
67
|
-
}
|
|
68
|
-
|
|
66
|
+
[resource = m_resource](dynamic args, Callback resolve, Callback reject) {
|
|
69
67
|
auto blob = jsArgAsObject(args, 0);
|
|
70
68
|
|
|
71
69
|
auto blobId = blob["blobId"].asString();
|
|
72
70
|
auto offset = blob["offset"].asInt();
|
|
73
71
|
auto size = blob["size"].asInt();
|
|
74
72
|
|
|
75
|
-
winrt::array_view<uint8_t const> bytes;
|
|
76
|
-
try {
|
|
77
|
-
bytes = blobPersistor->ResolveMessage(std::move(blobId), offset, size);
|
|
78
|
-
} catch (const std::exception &e) {
|
|
79
|
-
return reject({e.what()});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
auto result = string{"data:"};
|
|
83
73
|
auto typeItr = blob.find("type");
|
|
74
|
+
string type{};
|
|
84
75
|
if (typeItr == blob.items().end()) {
|
|
85
|
-
|
|
76
|
+
type = "application/octet-stream";
|
|
86
77
|
} else {
|
|
87
|
-
|
|
78
|
+
type = (*typeItr).second.asString();
|
|
88
79
|
}
|
|
89
|
-
result += ";base64,";
|
|
90
|
-
|
|
91
|
-
// https://www.boost.org/doc/libs/1_76_0/libs/serialization/doc/dataflow.html
|
|
92
|
-
using namespace boost::archive::iterators;
|
|
93
|
-
typedef base64_from_binary<transform_width<const char *, 6, 8>> encode_base64;
|
|
94
|
-
std::ostringstream oss;
|
|
95
|
-
std::copy(encode_base64(bytes.cbegin()), encode_base64(bytes.cend()), ostream_iterator<char>(oss));
|
|
96
|
-
result += oss.str();
|
|
97
80
|
|
|
98
|
-
|
|
81
|
+
resource->ReadAsDataUrl(
|
|
82
|
+
std::move(blobId),
|
|
83
|
+
offset,
|
|
84
|
+
size,
|
|
85
|
+
std::move(type),
|
|
86
|
+
[&resolve](string &&message) { resolve({std::move(message)}); },
|
|
87
|
+
[&reject](string &&message) { reject({std::move(message)}); });
|
|
99
88
|
}},
|
|
100
89
|
{///
|
|
101
90
|
/// <param name="args">
|
|
@@ -105,11 +94,7 @@ std::vector<module::CxxModule::Method> FileReaderModule::getMethods() {
|
|
|
105
94
|
/// </param>
|
|
106
95
|
///
|
|
107
96
|
"readAsText",
|
|
108
|
-
[
|
|
109
|
-
if (!blobPersistor) {
|
|
110
|
-
return reject({"Could not find Blob persistor"});
|
|
111
|
-
}
|
|
112
|
-
|
|
97
|
+
[resource = m_resource](dynamic args, Callback resolve, Callback reject) {
|
|
113
98
|
auto blob = jsArgAsObject(args, 0);
|
|
114
99
|
auto encoding = jsArgAsString(args, 1); // Default: "UTF-8"
|
|
115
100
|
|
|
@@ -117,18 +102,13 @@ std::vector<module::CxxModule::Method> FileReaderModule::getMethods() {
|
|
|
117
102
|
auto offset = blob["offset"].asInt();
|
|
118
103
|
auto size = blob["size"].asInt();
|
|
119
104
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
// #9982 - Handle non-UTF8 encodings
|
|
128
|
-
// See https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/charset/Charset.html
|
|
129
|
-
auto result = string{bytes.cbegin(), bytes.cend()};
|
|
130
|
-
|
|
131
|
-
resolve({std::move(result)});
|
|
105
|
+
resource->ReadAsText(
|
|
106
|
+
std::move(blobId),
|
|
107
|
+
offset,
|
|
108
|
+
size,
|
|
109
|
+
std::move(encoding),
|
|
110
|
+
[&resolve](string &&message) { resolve({std::move(message)}); },
|
|
111
|
+
[&reject](string &&message) { reject({std::move(message)}); });
|
|
132
112
|
}}};
|
|
133
113
|
}
|
|
134
114
|
|
|
@@ -136,14 +116,93 @@ std::vector<module::CxxModule::Method> FileReaderModule::getMethods() {
|
|
|
136
116
|
|
|
137
117
|
#pragma endregion FileReaderModule
|
|
138
118
|
|
|
119
|
+
#pragma region FileReaderTurboModule
|
|
120
|
+
|
|
121
|
+
void FileReaderTurboModule::Initialize(msrn::ReactContext const &reactContext) noexcept {
|
|
122
|
+
auto propId = msrn::ReactPropertyId<msrn::ReactNonAbiValue<weak_ptr<IBlobPersistor>>>{L"Blob.Persistor"};
|
|
123
|
+
auto props = reactContext.Properties();
|
|
124
|
+
auto prop = props.Get(propId);
|
|
125
|
+
m_resource = IFileReaderResource::Make(prop.Value());
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
///
|
|
129
|
+
/// <param name="data">
|
|
130
|
+
/// Blob object with the following fields:
|
|
131
|
+
/// - blobId
|
|
132
|
+
/// - offset
|
|
133
|
+
/// - size
|
|
134
|
+
/// - type (optional)
|
|
135
|
+
/// </param>
|
|
136
|
+
/// <param name="result">
|
|
137
|
+
/// Either resolves or rejects the current method with a given text message.
|
|
138
|
+
/// </param>
|
|
139
|
+
///
|
|
140
|
+
void FileReaderTurboModule::ReadAsDataUrl(msrn::JSValue &&data, msrn::ReactPromise<string> &&result) noexcept {
|
|
141
|
+
auto &blob = data.AsObject();
|
|
142
|
+
auto blobId = blob["blobId"].AsString();
|
|
143
|
+
auto offset = blob["offset"].AsInt64();
|
|
144
|
+
auto size = blob["size"].AsInt64();
|
|
145
|
+
|
|
146
|
+
auto typeItr = blob.find("type");
|
|
147
|
+
string type{};
|
|
148
|
+
if (typeItr == blob.end()) {
|
|
149
|
+
type = "application/octet-stream";
|
|
150
|
+
} else {
|
|
151
|
+
type = (*typeItr).second.AsString();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
m_resource->ReadAsDataUrl(
|
|
155
|
+
std::move(blobId),
|
|
156
|
+
offset,
|
|
157
|
+
size,
|
|
158
|
+
std::move(type),
|
|
159
|
+
[&result](string &&message) { result.Resolve(std::move(message)); },
|
|
160
|
+
[&result](string &&message) { result.Reject(winrt::to_hstring(std::move(message)).c_str()); });
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
///
|
|
164
|
+
/// <param name="data">
|
|
165
|
+
/// Blob object with the following fields:
|
|
166
|
+
/// - blobId
|
|
167
|
+
/// - offset
|
|
168
|
+
/// - size
|
|
169
|
+
/// - type (optional)
|
|
170
|
+
/// </param>
|
|
171
|
+
/// <param name="encoding">
|
|
172
|
+
/// Text encoding to proces data with.
|
|
173
|
+
/// </param>
|
|
174
|
+
/// <param name="result">
|
|
175
|
+
/// Either resolves or rejects the current method with a given text message.
|
|
176
|
+
/// </param>
|
|
177
|
+
///
|
|
178
|
+
void FileReaderTurboModule::ReadAsText(
|
|
179
|
+
msrn::JSValue &&data,
|
|
180
|
+
string &&encoding,
|
|
181
|
+
msrn::ReactPromise<string> &&result) noexcept {
|
|
182
|
+
auto &blob = data.AsObject();
|
|
183
|
+
auto blobId = blob["blobId"].AsString();
|
|
184
|
+
auto offset = blob["offset"].AsInt64();
|
|
185
|
+
auto size = blob["size"].AsInt64();
|
|
186
|
+
|
|
187
|
+
m_resource->ReadAsText(
|
|
188
|
+
std::move(blobId),
|
|
189
|
+
offset,
|
|
190
|
+
size,
|
|
191
|
+
std::move(encoding),
|
|
192
|
+
[&result](string &&message) { result.Resolve(std::move(message)); },
|
|
193
|
+
[&result](string &&message) { result.Reject(winrt::to_hstring(std::move(message)).c_str()); });
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
#pragma endregion FileReaderTurboModule
|
|
197
|
+
|
|
139
198
|
/*extern*/ const char *GetFileReaderModuleName() noexcept {
|
|
140
|
-
return
|
|
199
|
+
return s_moduleName;
|
|
141
200
|
}
|
|
142
201
|
|
|
143
202
|
/*extern*/ std::unique_ptr<module::CxxModule> CreateFileReaderModule(
|
|
144
203
|
IInspectable const &inspectableProperties) noexcept {
|
|
145
|
-
auto propId = ReactPropertyId<ReactNonAbiValue<weak_ptr<IBlobPersistor>>>{L"Blob.Persistor"};
|
|
146
|
-
auto propBag = ReactPropertyBag{inspectableProperties.try_as<IReactPropertyBag>()};
|
|
204
|
+
auto propId = msrn::ReactPropertyId<msrn::ReactNonAbiValue<weak_ptr<IBlobPersistor>>>{L"Blob.Persistor"};
|
|
205
|
+
auto propBag = msrn::ReactPropertyBag{inspectableProperties.try_as<msrn::IReactPropertyBag>()};
|
|
147
206
|
|
|
148
207
|
if (auto prop = propBag.Get(propId)) {
|
|
149
208
|
auto weakBlobPersistor = prop.Value();
|
|
@@ -154,4 +213,12 @@ std::vector<module::CxxModule::Method> FileReaderModule::getMethods() {
|
|
|
154
213
|
return nullptr;
|
|
155
214
|
}
|
|
156
215
|
|
|
216
|
+
/*extern*/ const wchar_t *GetFileReaderTurboModuleName() noexcept {
|
|
217
|
+
return s_moduleNameW;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/*extern*/ const msrn::ReactModuleProvider &GetFileReaderModuleProvider() noexcept {
|
|
221
|
+
return s_moduleProvider;
|
|
222
|
+
}
|
|
223
|
+
|
|
157
224
|
} // namespace Microsoft::React
|
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
#pragma once
|
|
5
5
|
|
|
6
|
+
#include <NativeFileReaderModuleSpec.g.h>
|
|
7
|
+
|
|
8
|
+
#include <IFileReaderResource.h>
|
|
9
|
+
#include <NativeModules.h>
|
|
6
10
|
#include "IBlobPersistor.h"
|
|
7
11
|
|
|
8
12
|
// React Native
|
|
@@ -48,7 +52,29 @@ class FileReaderModule : public facebook::xplat::module::CxxModule {
|
|
|
48
52
|
#pragma endregion CxxModule
|
|
49
53
|
|
|
50
54
|
private:
|
|
51
|
-
std::
|
|
55
|
+
std::shared_ptr<IFileReaderResource> m_resource;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
REACT_MODULE(FileReaderTurboModule, L"FileReaderModule")
|
|
59
|
+
struct FileReaderTurboModule {
|
|
60
|
+
using ModuleSpec = ReactNativeSpecs::FileReaderModuleSpec;
|
|
61
|
+
|
|
62
|
+
REACT_INIT(Initialize)
|
|
63
|
+
void Initialize(winrt::Microsoft::ReactNative::ReactContext const &reactContext) noexcept;
|
|
64
|
+
|
|
65
|
+
REACT_METHOD(ReadAsDataUrl, L"readAsDataURL")
|
|
66
|
+
void ReadAsDataUrl(
|
|
67
|
+
winrt::Microsoft::ReactNative::JSValue &&data,
|
|
68
|
+
winrt::Microsoft::ReactNative::ReactPromise<std::string> &&result) noexcept;
|
|
69
|
+
|
|
70
|
+
REACT_METHOD(ReadAsText, L"readAsText")
|
|
71
|
+
void ReadAsText(
|
|
72
|
+
winrt::Microsoft::ReactNative::JSValue &&data,
|
|
73
|
+
std::string &&encoding,
|
|
74
|
+
winrt::Microsoft::ReactNative::ReactPromise<std::string> &&result) noexcept;
|
|
75
|
+
|
|
76
|
+
private:
|
|
77
|
+
std::shared_ptr<IFileReaderResource> m_resource;
|
|
52
78
|
};
|
|
53
79
|
|
|
54
80
|
} // namespace Microsoft::React
|