|
@@ -89,6 +89,7 @@ namespace winrt::ReactNativeWebView::implementation {
|
89
|
89
|
auto tag = this->GetValue(winrt::FrameworkElement::TagProperty()).as<winrt::IPropertyValue>().GetInt64();
|
90
|
90
|
m_webBridge = WebViewBridge::WebBridge(tag);
|
91
|
91
|
m_webBridge.MessagePostedEvent(winrt::auto_revoke, [ref = get_weak()](const int32_t& message) {
|
|
92
|
+ OutputDebugStringW(L"> ReactWebView:MessagePostedEvent");
|
92
|
93
|
if (auto self = ref.get()) {
|
93
|
94
|
self->OnMessagePosted(message);
|
94
|
95
|
}
|
|
@@ -100,6 +101,8 @@ namespace winrt::ReactNativeWebView::implementation {
|
100
|
101
|
void ReactWebView::OnMessagePosted(const int32_t& message)
|
101
|
102
|
{
|
102
|
103
|
// TODO: send to RN
|
|
104
|
+ // PostMessage(winrt::hstring(args.Value()));
|
|
105
|
+ OutputDebugStringW(L"> ReactWebView:OnMessagePosted received");
|
103
|
106
|
}
|
104
|
107
|
|
105
|
108
|
void ReactWebView::OnNavigationCompleted(winrt::WebView const& webView, winrt::WebViewNavigationCompletedEventArgs const& /*args*/) {
|
|
@@ -113,8 +116,14 @@ namespace winrt::ReactNativeWebView::implementation {
|
113
|
116
|
});
|
114
|
117
|
|
115
|
118
|
winrt::hstring windowAlert = L"window.alert = function (msg) {window.external.notify(`{\"type\":\"__alert\",\"message\":\"${msg}\"}`)};";
|
116
|
|
- winrt::hstring postMessage = L"window.ReactNativeWebView = {postMessage: function (data) {window.external.notify(String(data))}};";
|
117
|
|
- webView.InvokeScriptAsync(L"eval", { windowAlert + postMessage });
|
|
119
|
+ if (m_messagingEnabled) {
|
|
120
|
+ winrt::hstring postMessage = L"window.ReactNativeWebView = {postMessage: function (data) {__RN_WEBVIEW_JS_BRIDGE.postMessage(String(data))}};";
|
|
121
|
+ webView.InvokeScriptAsync(L"eval", { windowAlert + postMessage });
|
|
122
|
+ }
|
|
123
|
+ else {
|
|
124
|
+ winrt::hstring postMessage = L"window.ReactNativeWebView = {postMessage: function (data) {window.external.notify(String(data))}};";
|
|
125
|
+ webView.InvokeScriptAsync(L"eval", { windowAlert + postMessage });
|
|
126
|
+ }
|
118
|
127
|
}
|
119
|
128
|
|
120
|
129
|
void ReactWebView::OnNavigationFailed(winrt::IInspectable const& /*sender*/, winrt::WebViewNavigationFailedEventArgs const& args) {
|