react-native-windows 0.70.0-preview.2 → 0.70.1
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/Microsoft.ReactNative/JSDispatcherWriter.cpp +60 -22
- package/Microsoft.ReactNative/JSDispatcherWriter.h +5 -3
- package/Microsoft.ReactNative/Pch/pch.h +0 -1
- package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +1 -0
- package/Microsoft.ReactNative/TurboModulesProvider.cpp +146 -84
- package/Microsoft.ReactNative/TurboModulesProvider.h +5 -0
- package/Microsoft.ReactNative/Views/ViewManagerBase.cpp +4 -2
- package/Microsoft.ReactNative.Cxx/JSI/LongLivedJsiValue.h +84 -0
- package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems +1 -0
- package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems.filters +3 -0
- package/Mso/src/dispatchQueue/uiScheduler_winrt.cpp +6 -1
- package/PropertySheets/Generated/PackageVersion.g.props +2 -2
- package/Shared/InstanceManager.cpp +29 -0
- package/Shared/InstanceManager.h +14 -0
- package/Shared/Modules/HttpModule.cpp +4 -2
- package/Shared/Networking/IHttpResource.h +1 -1
- package/Shared/Networking/IRedirectEventSource.h +18 -0
- package/Shared/Networking/IWinRTHttpRequestFactory.h +22 -0
- package/Shared/Networking/OriginPolicyHttpFilter.cpp +47 -16
- package/Shared/Networking/OriginPolicyHttpFilter.h +16 -3
- package/Shared/Networking/RedirectHttpFilter.cpp +283 -0
- package/Shared/Networking/RedirectHttpFilter.h +97 -0
- package/Shared/Networking/WinRTHttpResource.cpp +207 -154
- package/Shared/Networking/WinRTHttpResource.h +17 -4
- package/Shared/OInstance.cpp +16 -1
- package/Shared/OInstance.h +4 -13
- package/Shared/Shared.vcxitems +4 -0
- package/Shared/Shared.vcxitems.filters +12 -0
- package/package.json +8 -8
|
@@ -8,35 +8,57 @@
|
|
|
8
8
|
|
|
9
9
|
namespace winrt::Microsoft::ReactNative {
|
|
10
10
|
|
|
11
|
+
// Special IJSValueWriter that does nothing.
|
|
12
|
+
// We use it instead of JsiWriter when JSI runtime is not available anymore.
|
|
13
|
+
struct JSNoopWriter : winrt::implements<JSNoopWriter, IJSValueWriter> {
|
|
14
|
+
public: // IJSValueWriter
|
|
15
|
+
void WriteNull() noexcept;
|
|
16
|
+
void WriteBoolean(bool value) noexcept;
|
|
17
|
+
void WriteInt64(int64_t value) noexcept;
|
|
18
|
+
void WriteDouble(double value) noexcept;
|
|
19
|
+
void WriteString(const winrt::hstring &value) noexcept;
|
|
20
|
+
void WriteObjectBegin() noexcept;
|
|
21
|
+
void WritePropertyName(const winrt::hstring &name) noexcept;
|
|
22
|
+
void WriteObjectEnd() noexcept;
|
|
23
|
+
void WriteArrayBegin() noexcept;
|
|
24
|
+
void WriteArrayEnd() noexcept;
|
|
25
|
+
};
|
|
26
|
+
|
|
11
27
|
//===========================================================================
|
|
12
28
|
// JSDispatcherWriter implementation
|
|
13
29
|
//===========================================================================
|
|
14
30
|
|
|
15
31
|
JSDispatcherWriter::JSDispatcherWriter(
|
|
16
32
|
IReactDispatcher const &jsDispatcher,
|
|
17
|
-
|
|
18
|
-
: m_jsDispatcher(jsDispatcher),
|
|
33
|
+
std::weak_ptr<LongLivedJsiRuntime> jsiRuntimeHolder) noexcept
|
|
34
|
+
: m_jsDispatcher(jsDispatcher), m_jsiRuntimeHolder(std::move(jsiRuntimeHolder)) {}
|
|
19
35
|
|
|
20
36
|
void JSDispatcherWriter::WithResultArgs(
|
|
21
37
|
Mso::Functor<void(facebook::jsi::Runtime &rt, facebook::jsi::Value const *args, size_t argCount)>
|
|
22
38
|
handler) noexcept {
|
|
23
39
|
if (m_jsDispatcher.HasThreadAccess()) {
|
|
24
40
|
VerifyElseCrash(!m_dynamicWriter);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
41
|
+
if (auto jsiRuntimeHolder = m_jsiRuntimeHolder.lock()) {
|
|
42
|
+
const facebook::jsi::Value *args{nullptr};
|
|
43
|
+
size_t argCount{0};
|
|
44
|
+
m_jsiWriter->AccessResultAsArgs(args, argCount);
|
|
45
|
+
handler(jsiRuntimeHolder->Runtime(), args, argCount);
|
|
46
|
+
m_jsiWriter = nullptr;
|
|
47
|
+
}
|
|
29
48
|
} else {
|
|
30
49
|
VerifyElseCrash(!m_jsiWriter);
|
|
31
50
|
folly::dynamic dynValue = m_dynamicWriter->TakeValue();
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
51
|
+
VerifyElseCrash(dynValue.isArray());
|
|
52
|
+
m_jsDispatcher.Post([handler, dynValue = std::move(dynValue), weakJsiRuntimeHolder = m_jsiRuntimeHolder]() {
|
|
53
|
+
if (auto jsiRuntimeHolder = weakJsiRuntimeHolder.lock()) {
|
|
54
|
+
std::vector<facebook::jsi::Value> args;
|
|
55
|
+
args.reserve(dynValue.size());
|
|
56
|
+
auto &runtime = jsiRuntimeHolder->Runtime();
|
|
57
|
+
for (auto const &item : dynValue) {
|
|
58
|
+
args.emplace_back(facebook::jsi::valueFromDynamic(runtime, item));
|
|
59
|
+
}
|
|
60
|
+
handler(runtime, args.data(), args.size());
|
|
38
61
|
}
|
|
39
|
-
handler(runtime, args.data(), args.size());
|
|
40
62
|
});
|
|
41
63
|
}
|
|
42
64
|
}
|
|
@@ -82,20 +104,36 @@ void JSDispatcherWriter::WriteArrayEnd() noexcept {
|
|
|
82
104
|
}
|
|
83
105
|
|
|
84
106
|
IJSValueWriter JSDispatcherWriter::GetWriter() noexcept {
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
107
|
+
if (!m_writer) {
|
|
108
|
+
if (m_jsDispatcher.HasThreadAccess()) {
|
|
109
|
+
if (auto jsiRuntimeHolder = m_jsiRuntimeHolder.lock()) {
|
|
110
|
+
m_jsiWriter = winrt::make_self<JsiWriter>(jsiRuntimeHolder->Runtime());
|
|
111
|
+
m_writer = m_jsiWriter.as<IJSValueWriter>();
|
|
112
|
+
} else {
|
|
113
|
+
m_writer = winrt::make<JSNoopWriter>();
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
94
116
|
m_dynamicWriter = winrt::make_self<DynamicWriter>();
|
|
95
117
|
m_writer = m_dynamicWriter.as<IJSValueWriter>();
|
|
96
118
|
}
|
|
97
119
|
}
|
|
120
|
+
Debug(VerifyElseCrash(m_dynamicWriter != nullptr || m_jsDispatcher.HasThreadAccess()));
|
|
98
121
|
return m_writer;
|
|
99
122
|
}
|
|
100
123
|
|
|
124
|
+
//===========================================================================
|
|
125
|
+
// JSNoopWriter implementation
|
|
126
|
+
//===========================================================================
|
|
127
|
+
|
|
128
|
+
void JSNoopWriter::WriteNull() noexcept {}
|
|
129
|
+
void JSNoopWriter::WriteBoolean(bool /*value*/) noexcept {}
|
|
130
|
+
void JSNoopWriter::WriteInt64(int64_t /*value*/) noexcept {}
|
|
131
|
+
void JSNoopWriter::WriteDouble(double /*value*/) noexcept {}
|
|
132
|
+
void JSNoopWriter::WriteString(const winrt::hstring & /*value*/) noexcept {}
|
|
133
|
+
void JSNoopWriter::WriteObjectBegin() noexcept {}
|
|
134
|
+
void JSNoopWriter::WritePropertyName(const winrt::hstring & /*name*/) noexcept {}
|
|
135
|
+
void JSNoopWriter::WriteObjectEnd() noexcept {}
|
|
136
|
+
void JSNoopWriter::WriteArrayBegin() noexcept {}
|
|
137
|
+
void JSNoopWriter::WriteArrayEnd() noexcept {}
|
|
138
|
+
|
|
101
139
|
} // namespace winrt::Microsoft::ReactNative
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
#pragma once
|
|
4
4
|
|
|
5
|
+
#include <JSI/LongLivedJsiValue.h>
|
|
5
6
|
#include <functional/functor.h>
|
|
6
7
|
#include "DynamicWriter.h"
|
|
7
8
|
#include "JsiWriter.h"
|
|
8
|
-
#include "folly/dynamic.h"
|
|
9
9
|
#include "winrt/Microsoft.ReactNative.h"
|
|
10
10
|
|
|
11
11
|
namespace winrt::Microsoft::ReactNative {
|
|
@@ -14,7 +14,9 @@ namespace winrt::Microsoft::ReactNative {
|
|
|
14
14
|
// In case if writing is done outside of JSDispatcher, it uses DynamicWriter to create
|
|
15
15
|
// folly::dynamic which then is written to JsiWriter in JSDispatcher.
|
|
16
16
|
struct JSDispatcherWriter : winrt::implements<JSDispatcherWriter, IJSValueWriter> {
|
|
17
|
-
JSDispatcherWriter(
|
|
17
|
+
JSDispatcherWriter(
|
|
18
|
+
IReactDispatcher const &jsDispatcher,
|
|
19
|
+
std::weak_ptr<LongLivedJsiRuntime> jsiRuntimeHolder) noexcept;
|
|
18
20
|
void WithResultArgs(Mso::Functor<void(facebook::jsi::Runtime &rt, facebook::jsi::Value const *args, size_t argCount)>
|
|
19
21
|
handler) noexcept;
|
|
20
22
|
|
|
@@ -35,7 +37,7 @@ struct JSDispatcherWriter : winrt::implements<JSDispatcherWriter, IJSValueWriter
|
|
|
35
37
|
|
|
36
38
|
private:
|
|
37
39
|
IReactDispatcher m_jsDispatcher;
|
|
38
|
-
|
|
40
|
+
std::weak_ptr<LongLivedJsiRuntime> m_jsiRuntimeHolder;
|
|
39
41
|
winrt::com_ptr<DynamicWriter> m_dynamicWriter;
|
|
40
42
|
winrt::com_ptr<JsiWriter> m_jsiWriter;
|
|
41
43
|
IJSValueWriter m_writer;
|
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
#include <winrt/Windows.Storage.Streams.h>
|
|
44
44
|
#include <winrt/Windows.UI.ViewManagement.Core.h>
|
|
45
45
|
#include <winrt/Windows.UI.ViewManagement.h>
|
|
46
|
-
#include <winrt/Windows.Web.Http.Filters.h>
|
|
47
46
|
#include <winrt/Windows.Web.Http.Headers.h>
|
|
48
47
|
|
|
49
48
|
#include "Base/CxxReactIncludes.h"
|
|
@@ -510,6 +510,7 @@ void ReactInstanceWin::Initialize() noexcept {
|
|
|
510
510
|
std::move(bundleRootPath), // bundleRootPath
|
|
511
511
|
std::move(cxxModules),
|
|
512
512
|
m_options.TurboModuleProvider,
|
|
513
|
+
m_options.TurboModuleProvider->LongLivedObjectCollection(),
|
|
513
514
|
std::make_unique<BridgeUIBatchInstanceCallback>(weakThis),
|
|
514
515
|
m_jsMessageThread.Load(),
|
|
515
516
|
m_nativeMessageThread.Load(),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
|
+
//
|
|
3
4
|
// IMPORTANT: Before updating this file
|
|
4
5
|
// please read react-native-windows repo:
|
|
5
6
|
// vnext/Microsoft.ReactNative.Cxx/README.md
|
|
@@ -21,6 +22,7 @@ using namespace winrt;
|
|
|
21
22
|
using namespace Windows::Foundation;
|
|
22
23
|
|
|
23
24
|
namespace winrt::Microsoft::ReactNative {
|
|
25
|
+
|
|
24
26
|
/*-------------------------------------------------------------------------------
|
|
25
27
|
TurboModuleBuilder
|
|
26
28
|
-------------------------------------------------------------------------------*/
|
|
@@ -56,10 +58,17 @@ struct TurboModuleBuilder : winrt::implements<TurboModuleBuilder, IReactModuleBu
|
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
public:
|
|
59
|
-
std::unordered_map<std::string, TurboModuleMethodInfo>
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
const std::unordered_map<std::string, TurboModuleMethodInfo> &Methods() const noexcept {
|
|
62
|
+
return m_methods;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const std::unordered_map<std::string, SyncMethodDelegate> &SyncMethods() const noexcept {
|
|
66
|
+
return m_syncMethods;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const std::vector<ConstantProviderDelegate> &ConstantProviders() const noexcept {
|
|
70
|
+
return m_constantProviders;
|
|
71
|
+
}
|
|
63
72
|
|
|
64
73
|
private:
|
|
65
74
|
void EnsureMemberNotSet(const std::string &key, bool checkingMethod) noexcept {
|
|
@@ -72,6 +81,10 @@ struct TurboModuleBuilder : winrt::implements<TurboModuleBuilder, IReactModuleBu
|
|
|
72
81
|
|
|
73
82
|
private:
|
|
74
83
|
IReactContext m_reactContext;
|
|
84
|
+
std::unordered_map<std::string, TurboModuleMethodInfo> m_methods;
|
|
85
|
+
std::unordered_map<std::string, SyncMethodDelegate> m_syncMethods;
|
|
86
|
+
std::vector<ConstantProviderDelegate> m_constantProviders;
|
|
87
|
+
bool m_constantsEvaluated{false};
|
|
75
88
|
};
|
|
76
89
|
|
|
77
90
|
/*-------------------------------------------------------------------------------
|
|
@@ -84,11 +97,13 @@ class TurboModuleImpl : public facebook::react::TurboModule {
|
|
|
84
97
|
const IReactContext &reactContext,
|
|
85
98
|
const std::string &name,
|
|
86
99
|
const std::shared_ptr<facebook::react::CallInvoker> &jsInvoker,
|
|
100
|
+
std::weak_ptr<facebook::react::LongLivedObjectCollection> longLivedObjectCollection,
|
|
87
101
|
const ReactModuleProvider &reactModuleProvider)
|
|
88
102
|
: facebook::react::TurboModule(name, jsInvoker),
|
|
89
103
|
m_reactContext(reactContext),
|
|
90
|
-
|
|
91
|
-
|
|
104
|
+
m_longLivedObjectCollection(std::move(longLivedObjectCollection)),
|
|
105
|
+
m_moduleBuilder(winrt::make_self<TurboModuleBuilder>(reactContext)),
|
|
106
|
+
m_providedModule(reactModuleProvider(m_moduleBuilder.as<IReactModuleBuilder>())) {
|
|
92
107
|
if (auto hostObject = m_providedModule.try_as<IJsiHostObject>()) {
|
|
93
108
|
m_hostObjectWrapper = std::make_shared<implementation::HostObjectWrapper>(hostObject);
|
|
94
109
|
}
|
|
@@ -99,12 +114,23 @@ class TurboModuleImpl : public facebook::react::TurboModule {
|
|
|
99
114
|
return m_hostObjectWrapper->getPropertyNames(rt);
|
|
100
115
|
}
|
|
101
116
|
|
|
102
|
-
auto turboModuleBuilder = m_moduleBuilder.as<TurboModuleBuilder>();
|
|
103
117
|
std::vector<facebook::jsi::PropNameID> propertyNames;
|
|
104
|
-
propertyNames.reserve(
|
|
105
|
-
|
|
118
|
+
propertyNames.reserve(
|
|
119
|
+
m_moduleBuilder->Methods().size() + m_moduleBuilder->SyncMethods().size() +
|
|
120
|
+
(m_moduleBuilder->ConstantProviders().empty() ? 0 : 1));
|
|
121
|
+
|
|
122
|
+
for (auto &methodInfo : m_moduleBuilder->Methods()) {
|
|
106
123
|
propertyNames.push_back(facebook::jsi::PropNameID::forAscii(rt, methodInfo.first));
|
|
107
124
|
}
|
|
125
|
+
|
|
126
|
+
for (auto &syncMethodInfo : m_moduleBuilder->SyncMethods()) {
|
|
127
|
+
propertyNames.push_back(facebook::jsi::PropNameID::forAscii(rt, syncMethodInfo.first));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (!m_moduleBuilder->ConstantProviders().empty()) {
|
|
131
|
+
propertyNames.push_back(facebook::jsi::PropNameID::forAscii(rt, "getConstants"));
|
|
132
|
+
}
|
|
133
|
+
|
|
108
134
|
return propertyNames;
|
|
109
135
|
};
|
|
110
136
|
|
|
@@ -114,24 +140,23 @@ class TurboModuleImpl : public facebook::react::TurboModule {
|
|
|
114
140
|
}
|
|
115
141
|
|
|
116
142
|
// it is not safe to assume that "runtime" never changes, so members are not cached here
|
|
117
|
-
auto moduleBuilder = m_moduleBuilder.as<TurboModuleBuilder>();
|
|
118
143
|
std::string key = propName.utf8(runtime);
|
|
119
144
|
|
|
120
|
-
if (key == "getConstants" && !
|
|
145
|
+
if (key == "getConstants" && !m_moduleBuilder->ConstantProviders().empty()) {
|
|
121
146
|
// try to find getConstants if there is any constant
|
|
122
147
|
return facebook::jsi::Function::createFromHostFunction(
|
|
123
148
|
runtime,
|
|
124
149
|
propName,
|
|
125
150
|
0,
|
|
126
|
-
[moduleBuilder](
|
|
151
|
+
[moduleBuilder = m_moduleBuilder](
|
|
127
152
|
facebook::jsi::Runtime &rt,
|
|
128
|
-
const facebook::jsi::Value &thisVal
|
|
129
|
-
const facebook::jsi::Value *args
|
|
130
|
-
size_t count) {
|
|
153
|
+
const facebook::jsi::Value & /*thisVal*/,
|
|
154
|
+
const facebook::jsi::Value * /*args*/,
|
|
155
|
+
size_t /*count*/) {
|
|
131
156
|
// collect all constants to an object
|
|
132
157
|
auto writer = winrt::make<JsiWriter>(rt);
|
|
133
158
|
writer.WriteObjectBegin();
|
|
134
|
-
for (auto constantProvider : moduleBuilder->
|
|
159
|
+
for (auto const &constantProvider : moduleBuilder->ConstantProviders()) {
|
|
135
160
|
constantProvider(writer);
|
|
136
161
|
}
|
|
137
162
|
writer.WriteObjectEnd();
|
|
@@ -141,21 +166,21 @@ class TurboModuleImpl : public facebook::react::TurboModule {
|
|
|
141
166
|
|
|
142
167
|
{
|
|
143
168
|
// try to find a Method
|
|
144
|
-
auto it =
|
|
145
|
-
if (it !=
|
|
146
|
-
TurboModuleMethodInfo methodInfo = it->second;
|
|
169
|
+
auto it = m_moduleBuilder->Methods().find(key);
|
|
170
|
+
if (it != m_moduleBuilder->Methods().end()) {
|
|
171
|
+
TurboModuleMethodInfo const &methodInfo = it->second;
|
|
147
172
|
switch (methodInfo.ReturnType) {
|
|
148
173
|
case MethodReturnType::Void:
|
|
149
174
|
return facebook::jsi::Function::createFromHostFunction(
|
|
150
175
|
runtime,
|
|
151
176
|
propName,
|
|
152
177
|
0,
|
|
153
|
-
[methodInfo](
|
|
178
|
+
[method = methodInfo.Method](
|
|
154
179
|
facebook::jsi::Runtime &rt,
|
|
155
180
|
const facebook::jsi::Value & /*thisVal*/,
|
|
156
181
|
const facebook::jsi::Value *args,
|
|
157
182
|
size_t argCount) {
|
|
158
|
-
|
|
183
|
+
method(winrt::make<JsiReader>(rt, args, argCount), nullptr, nullptr, nullptr);
|
|
159
184
|
return facebook::jsi::Value::undefined();
|
|
160
185
|
});
|
|
161
186
|
case MethodReturnType::Callback:
|
|
@@ -163,17 +188,22 @@ class TurboModuleImpl : public facebook::react::TurboModule {
|
|
|
163
188
|
runtime,
|
|
164
189
|
propName,
|
|
165
190
|
0,
|
|
166
|
-
[jsDispatcher = m_reactContext.JSDispatcher(),
|
|
191
|
+
[jsDispatcher = m_reactContext.JSDispatcher(),
|
|
192
|
+
method = methodInfo.Method,
|
|
193
|
+
longLivedObjectCollection = m_longLivedObjectCollection](
|
|
167
194
|
facebook::jsi::Runtime &rt,
|
|
168
195
|
const facebook::jsi::Value & /*thisVal*/,
|
|
169
196
|
const facebook::jsi::Value *args,
|
|
170
197
|
size_t argCount) {
|
|
171
198
|
VerifyElseCrash(argCount > 0);
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
199
|
+
if (auto strongLongLivedObjectCollection = longLivedObjectCollection.lock()) {
|
|
200
|
+
auto jsiRuntimeHolder = LongLivedJsiRuntime::CreateWeak(strongLongLivedObjectCollection, rt);
|
|
201
|
+
method(
|
|
202
|
+
winrt::make<JsiReader>(rt, args, argCount - 1),
|
|
203
|
+
winrt::make<JSDispatcherWriter>(jsDispatcher, jsiRuntimeHolder),
|
|
204
|
+
MakeCallback(rt, strongLongLivedObjectCollection, args[argCount - 1]),
|
|
205
|
+
nullptr);
|
|
206
|
+
}
|
|
177
207
|
return facebook::jsi::Value::undefined();
|
|
178
208
|
});
|
|
179
209
|
case MethodReturnType::TwoCallbacks:
|
|
@@ -181,17 +211,22 @@ class TurboModuleImpl : public facebook::react::TurboModule {
|
|
|
181
211
|
runtime,
|
|
182
212
|
propName,
|
|
183
213
|
0,
|
|
184
|
-
[jsDispatcher = m_reactContext.JSDispatcher(),
|
|
214
|
+
[jsDispatcher = m_reactContext.JSDispatcher(),
|
|
215
|
+
method = methodInfo.Method,
|
|
216
|
+
longLivedObjectCollection = m_longLivedObjectCollection](
|
|
185
217
|
facebook::jsi::Runtime &rt,
|
|
186
218
|
const facebook::jsi::Value & /*thisVal*/,
|
|
187
219
|
const facebook::jsi::Value *args,
|
|
188
220
|
size_t argCount) {
|
|
189
221
|
VerifyElseCrash(argCount > 1);
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
222
|
+
if (auto strongLongLivedObjectCollection = longLivedObjectCollection.lock()) {
|
|
223
|
+
auto jsiRuntimeHolder = LongLivedJsiRuntime::CreateWeak(strongLongLivedObjectCollection, rt);
|
|
224
|
+
method(
|
|
225
|
+
winrt::make<JsiReader>(rt, args, argCount - 2),
|
|
226
|
+
winrt::make<JSDispatcherWriter>(jsDispatcher, jsiRuntimeHolder),
|
|
227
|
+
MakeCallback(rt, strongLongLivedObjectCollection, args[argCount - 2]),
|
|
228
|
+
MakeCallback(rt, strongLongLivedObjectCollection, args[argCount - 1]));
|
|
229
|
+
}
|
|
195
230
|
return facebook::jsi::Value::undefined();
|
|
196
231
|
});
|
|
197
232
|
case MethodReturnType::Promise:
|
|
@@ -199,52 +234,66 @@ class TurboModuleImpl : public facebook::react::TurboModule {
|
|
|
199
234
|
runtime,
|
|
200
235
|
propName,
|
|
201
236
|
0,
|
|
202
|
-
[jsDispatcher = m_reactContext.JSDispatcher(),
|
|
237
|
+
[jsDispatcher = m_reactContext.JSDispatcher(),
|
|
238
|
+
method = methodInfo.Method,
|
|
239
|
+
longLivedObjectCollection = m_longLivedObjectCollection](
|
|
203
240
|
facebook::jsi::Runtime &rt,
|
|
204
241
|
const facebook::jsi::Value & /*thisVal*/,
|
|
205
242
|
const facebook::jsi::Value *args,
|
|
206
243
|
size_t count) {
|
|
207
|
-
auto
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
244
|
+
if (auto strongLongLivedObjectCollection = longLivedObjectCollection.lock()) {
|
|
245
|
+
auto jsiRuntimeHolder = LongLivedJsiRuntime::CreateWeak(strongLongLivedObjectCollection, rt);
|
|
246
|
+
auto argReader = winrt::make<JsiReader>(rt, args, count);
|
|
247
|
+
auto argWriter = winrt::make<JSDispatcherWriter>(jsDispatcher, jsiRuntimeHolder);
|
|
248
|
+
return facebook::react::createPromiseAsJSIValue(
|
|
249
|
+
rt,
|
|
250
|
+
[method, argReader, argWriter, strongLongLivedObjectCollection](
|
|
251
|
+
facebook::jsi::Runtime &runtime, std::shared_ptr<facebook::react::Promise> promise) {
|
|
252
|
+
method(
|
|
253
|
+
argReader,
|
|
254
|
+
argWriter,
|
|
255
|
+
[weakResolve = LongLivedJsiFunction::CreateWeak(
|
|
256
|
+
strongLongLivedObjectCollection, runtime, std::move(promise->resolve_))](
|
|
257
|
+
const IJSValueWriter &writer) {
|
|
258
|
+
writer.as<JSDispatcherWriter>()->WithResultArgs([weakResolve](
|
|
259
|
+
facebook::jsi::Runtime &runtime,
|
|
260
|
+
facebook::jsi::Value const *args,
|
|
261
|
+
size_t argCount) {
|
|
262
|
+
VerifyElseCrash(argCount == 1);
|
|
263
|
+
if (auto resolveHolder = weakResolve.lock()) {
|
|
264
|
+
resolveHolder->Value().call(runtime, args[0]);
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
},
|
|
268
|
+
[weakReject = LongLivedJsiFunction::CreateWeak(
|
|
269
|
+
strongLongLivedObjectCollection, runtime, std::move(promise->reject_))](
|
|
270
|
+
const IJSValueWriter &writer) {
|
|
271
|
+
writer.as<JSDispatcherWriter>()->WithResultArgs([weakReject](
|
|
272
|
+
facebook::jsi::Runtime &runtime,
|
|
273
|
+
facebook::jsi::Value const *args,
|
|
274
|
+
size_t argCount) {
|
|
275
|
+
VerifyElseCrash(argCount == 1);
|
|
276
|
+
if (auto rejectHolder = weakReject.lock()) {
|
|
277
|
+
// To match the Android and iOS TurboModule behavior we create the Error object for
|
|
278
|
+
// the Promise rejection the same way as in updateErrorWithErrorData method.
|
|
279
|
+
// See react-native/Libraries/BatchedBridge/NativeModules.js for details.
|
|
280
|
+
auto error = runtime.global()
|
|
281
|
+
.getPropertyAsFunction(runtime, "Error")
|
|
282
|
+
.callAsConstructor(runtime, {});
|
|
283
|
+
auto &errorData = args[0];
|
|
284
|
+
if (errorData.isObject()) {
|
|
285
|
+
runtime.global()
|
|
286
|
+
.getPropertyAsObject(runtime, "Object")
|
|
287
|
+
.getPropertyAsFunction(runtime, "assign")
|
|
288
|
+
.call(runtime, error, errorData.getObject(runtime));
|
|
289
|
+
}
|
|
290
|
+
rejectHolder->Value().call(runtime, args[0]);
|
|
291
|
+
}
|
|
292
|
+
});
|
|
223
293
|
});
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
facebook::jsi::Runtime &runtime,
|
|
228
|
-
facebook::jsi::Value const *args,
|
|
229
|
-
size_t argCount) {
|
|
230
|
-
VerifyElseCrash(argCount == 1);
|
|
231
|
-
// To match the Android and iOS TurboModule behavior we create the Error object for
|
|
232
|
-
// the Promise rejection the same way as in updateErrorWithErrorData method.
|
|
233
|
-
// See react-native/Libraries/BatchedBridge/NativeModules.js for details.
|
|
234
|
-
auto error = runtime.global()
|
|
235
|
-
.getPropertyAsFunction(runtime, "Error")
|
|
236
|
-
.callAsConstructor(runtime, {});
|
|
237
|
-
auto &errorData = args[0];
|
|
238
|
-
if (errorData.isObject()) {
|
|
239
|
-
runtime.global()
|
|
240
|
-
.getPropertyAsObject(runtime, "Object")
|
|
241
|
-
.getPropertyAsFunction(runtime, "assign")
|
|
242
|
-
.call(runtime, error, errorData.getObject(runtime));
|
|
243
|
-
}
|
|
244
|
-
promise->reject_.call(runtime, error);
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
});
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
return facebook::jsi::Value::undefined();
|
|
248
297
|
});
|
|
249
298
|
default:
|
|
250
299
|
VerifyElseCrash(false);
|
|
@@ -254,8 +303,8 @@ class TurboModuleImpl : public facebook::react::TurboModule {
|
|
|
254
303
|
|
|
255
304
|
{
|
|
256
305
|
// try to find a SyncMethod
|
|
257
|
-
auto it =
|
|
258
|
-
if (it !=
|
|
306
|
+
auto it = m_moduleBuilder->SyncMethods().find(key);
|
|
307
|
+
if (it != m_moduleBuilder->SyncMethods().end()) {
|
|
259
308
|
return facebook::jsi::Function::createFromHostFunction(
|
|
260
309
|
runtime,
|
|
261
310
|
propName,
|
|
@@ -287,27 +336,34 @@ class TurboModuleImpl : public facebook::react::TurboModule {
|
|
|
287
336
|
}
|
|
288
337
|
|
|
289
338
|
private:
|
|
290
|
-
static MethodResultCallback MakeCallback(
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
339
|
+
static MethodResultCallback MakeCallback(
|
|
340
|
+
facebook::jsi::Runtime &rt,
|
|
341
|
+
const std::shared_ptr<facebook::react::LongLivedObjectCollection> &longLivedObjectCollection,
|
|
342
|
+
const facebook::jsi::Value &callback) noexcept {
|
|
343
|
+
auto weakCallback =
|
|
344
|
+
LongLivedJsiFunction::CreateWeak(longLivedObjectCollection, rt, callback.getObject(rt).getFunction(rt));
|
|
345
|
+
return [weakCallback = std::move(weakCallback)](const IJSValueWriter &writer) noexcept {
|
|
294
346
|
writer.as<JSDispatcherWriter>()->WithResultArgs(
|
|
295
|
-
[
|
|
296
|
-
|
|
347
|
+
[weakCallback](facebook::jsi::Runtime &rt, facebook::jsi::Value const *args, size_t count) {
|
|
348
|
+
if (auto callback = weakCallback.lock()) {
|
|
349
|
+
callback->Value().call(rt, args, count);
|
|
350
|
+
}
|
|
297
351
|
});
|
|
298
352
|
};
|
|
299
353
|
}
|
|
300
354
|
|
|
301
355
|
private:
|
|
302
356
|
IReactContext m_reactContext;
|
|
303
|
-
|
|
357
|
+
winrt::com_ptr<TurboModuleBuilder> m_moduleBuilder;
|
|
304
358
|
IInspectable m_providedModule;
|
|
305
359
|
std::shared_ptr<implementation::HostObjectWrapper> m_hostObjectWrapper;
|
|
360
|
+
std::weak_ptr<facebook::react::LongLivedObjectCollection> m_longLivedObjectCollection;
|
|
306
361
|
};
|
|
307
362
|
|
|
308
363
|
/*-------------------------------------------------------------------------------
|
|
309
364
|
TurboModulesProvider
|
|
310
365
|
-------------------------------------------------------------------------------*/
|
|
366
|
+
|
|
311
367
|
std::shared_ptr<facebook::react::TurboModule> TurboModulesProvider::getModule(
|
|
312
368
|
const std::string &moduleName,
|
|
313
369
|
const std::shared_ptr<facebook::react::CallInvoker> &callInvoker) noexcept {
|
|
@@ -317,7 +373,8 @@ std::shared_ptr<facebook::react::TurboModule> TurboModulesProvider::getModule(
|
|
|
317
373
|
return nullptr;
|
|
318
374
|
}
|
|
319
375
|
|
|
320
|
-
auto tm = std::make_shared<TurboModuleImpl>(
|
|
376
|
+
auto tm = std::make_shared<TurboModuleImpl>(
|
|
377
|
+
m_reactContext, moduleName, callInvoker, m_longLivedObjectCollection, /*reactModuleProvider*/ it->second);
|
|
321
378
|
return tm;
|
|
322
379
|
}
|
|
323
380
|
|
|
@@ -348,4 +405,9 @@ void TurboModulesProvider::AddModuleProvider(
|
|
|
348
405
|
}
|
|
349
406
|
}
|
|
350
407
|
|
|
408
|
+
std::shared_ptr<facebook::react::LongLivedObjectCollection> const &
|
|
409
|
+
TurboModulesProvider::LongLivedObjectCollection() noexcept {
|
|
410
|
+
return m_longLivedObjectCollection;
|
|
411
|
+
}
|
|
412
|
+
|
|
351
413
|
} // namespace winrt::Microsoft::ReactNative
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
#pragma once
|
|
8
8
|
|
|
9
|
+
#include <ReactCommon/LongLivedObject.h>
|
|
9
10
|
#include <TurboModuleRegistry.h>
|
|
10
11
|
#include "Base/FollyIncludes.h"
|
|
11
12
|
#include "winrt/Microsoft.ReactNative.h"
|
|
@@ -25,8 +26,12 @@ class TurboModulesProvider final : public facebook::react::TurboModuleRegistry {
|
|
|
25
26
|
winrt::hstring const &moduleName,
|
|
26
27
|
ReactModuleProvider const &moduleProvider,
|
|
27
28
|
bool overwriteExisting) noexcept;
|
|
29
|
+
std::shared_ptr<facebook::react::LongLivedObjectCollection> const &LongLivedObjectCollection() noexcept;
|
|
28
30
|
|
|
29
31
|
private:
|
|
32
|
+
// To keep a list of deferred asynchronous callbacks and promises.
|
|
33
|
+
std::shared_ptr<facebook::react::LongLivedObjectCollection> m_longLivedObjectCollection{
|
|
34
|
+
std::make_shared<facebook::react::LongLivedObjectCollection>()};
|
|
30
35
|
std::unordered_map<std::string, ReactModuleProvider> m_moduleProviders;
|
|
31
36
|
IReactContext m_reactContext;
|
|
32
37
|
};
|
|
@@ -271,9 +271,11 @@ bool ViewManagerBase::UpdateProperty(
|
|
|
271
271
|
const auto iter = pointerEventsMap.find(propertyValue.AsString());
|
|
272
272
|
if (iter != pointerEventsMap.end()) {
|
|
273
273
|
nodeToUpdate->m_pointerEvents = iter->second;
|
|
274
|
-
if (nodeToUpdate->
|
|
275
|
-
if (
|
|
274
|
+
if (const auto uiElement = nodeToUpdate->GetView().try_as<xaml::UIElement>()) {
|
|
275
|
+
if (nodeToUpdate->m_pointerEvents == PointerEventsKind::None) {
|
|
276
276
|
uiElement.IsHitTestVisible(false);
|
|
277
|
+
} else {
|
|
278
|
+
uiElement.ClearValue(xaml::UIElement::IsHitTestVisibleProperty());
|
|
277
279
|
}
|
|
278
280
|
}
|
|
279
281
|
} else {
|