|
@@ -97,7 +97,7 @@ namespace winrt::ReactNativeWebView::implementation {
|
97
|
97
|
eventDataWriter.WriteObjectEnd();
|
98
|
98
|
});
|
99
|
99
|
|
100
|
|
- winrt::hstring windowAlert = L"window.alert = function (msg) {window.external.notify(`{\"type\":\"alert\",\"message\":\"${msg}\"}`)};";
|
|
100
|
+ winrt::hstring windowAlert = L"window.alert = function (msg) {window.external.notify(`{\"type\":\"__alert\",\"message\":\"${msg}\"}`)};";
|
101
|
101
|
winrt::hstring postMessage = L"window.ReactNativeWebView = {postMessage: function (data) {window.external.notify(String(data))}};";
|
102
|
102
|
m_webView.InvokeScriptAsync(L"eval", { windowAlert + postMessage });
|
103
|
103
|
}
|
|
@@ -119,26 +119,26 @@ namespace winrt::ReactNativeWebView::implementation {
|
119
|
119
|
|
120
|
120
|
void ReactWebView::OnScriptNotify(winrt::IInspectable const& /*sender*/, winrt::Windows::UI::Xaml::Controls::NotifyEventArgs const& args) {
|
121
|
121
|
winrt::JsonObject jsonObject;
|
122
|
|
- if (winrt::JsonObject::TryParse(args.Value(), jsonObject)) {
|
|
122
|
+ if (winrt::JsonObject::TryParse(args.Value(), jsonObject) && jsonObject.HasKey(L"type")) {
|
123
|
123
|
auto type = jsonObject.GetNamedString(L"type");
|
124
|
|
- if (type == L"alert") {
|
|
124
|
+ if (type == L"__alert") {
|
125
|
125
|
auto dialog = winrt::MessageDialog(jsonObject.GetNamedString(L"message"));
|
126
|
126
|
dialog.Commands().Append(winrt::UICommand(L"OK"));
|
127
|
127
|
dialog.ShowAsync();
|
|
128
|
+ return;
|
128
|
129
|
}
|
129
|
130
|
}
|
130
|
|
- else {
|
131
|
|
- m_reactContext.DispatchEvent(
|
132
|
|
- m_webView,
|
133
|
|
- L"topMessage",
|
134
|
|
- [&](winrt::Microsoft::ReactNative::IJSValueWriter const& eventDataWriter) noexcept {
|
135
|
|
- eventDataWriter.WriteObjectBegin();
|
136
|
|
- {
|
137
|
|
- WriteProperty(eventDataWriter, L"data", winrt::to_string(args.Value()));
|
138
|
|
- }
|
139
|
|
- eventDataWriter.WriteObjectEnd();
|
140
|
|
- });
|
141
|
|
- }
|
|
131
|
+
|
|
132
|
+ m_reactContext.DispatchEvent(
|
|
133
|
+ m_webView,
|
|
134
|
+ L"topMessage",
|
|
135
|
+ [&](winrt::Microsoft::ReactNative::IJSValueWriter const& eventDataWriter) noexcept {
|
|
136
|
+ eventDataWriter.WriteObjectBegin();
|
|
137
|
+ {
|
|
138
|
+ WriteProperty(eventDataWriter, L"data", winrt::to_string(args.Value()));
|
|
139
|
+ }
|
|
140
|
+ eventDataWriter.WriteObjectEnd();
|
|
141
|
+ });
|
142
|
142
|
}
|
143
|
143
|
|
144
|
144
|
} // namespace winrt::ReactNativeWebView::implementation
|