Pārlūkot izejas kodu

Use bridge if messagingEnabled

Tero Paananen 4 gadus atpakaļ
vecāks
revīzija
55274858f2

+ 11
- 2
windows/ReactNativeWebView/ReactWebView.cpp Parādīt failu

89
           auto tag = this->GetValue(winrt::FrameworkElement::TagProperty()).as<winrt::IPropertyValue>().GetInt64();
89
           auto tag = this->GetValue(winrt::FrameworkElement::TagProperty()).as<winrt::IPropertyValue>().GetInt64();
90
           m_webBridge = WebViewBridge::WebBridge(tag);
90
           m_webBridge = WebViewBridge::WebBridge(tag);
91
           m_webBridge.MessagePostedEvent(winrt::auto_revoke, [ref = get_weak()](const int32_t& message) {
91
           m_webBridge.MessagePostedEvent(winrt::auto_revoke, [ref = get_weak()](const int32_t& message) {
92
+            OutputDebugStringW(L"> ReactWebView:MessagePostedEvent");
92
             if (auto self = ref.get()) {
93
             if (auto self = ref.get()) {
93
               self->OnMessagePosted(message);
94
               self->OnMessagePosted(message);
94
             }
95
             }
100
     void ReactWebView::OnMessagePosted(const int32_t& message)
101
     void ReactWebView::OnMessagePosted(const int32_t& message)
101
     {
102
     {
102
       // TODO: send to RN
103
       // TODO: send to RN
104
+      // PostMessage(winrt::hstring(args.Value()));
105
+      OutputDebugStringW(L"> ReactWebView:OnMessagePosted received");
103
     }
106
     }
104
 
107
 
105
     void ReactWebView::OnNavigationCompleted(winrt::WebView const& webView, winrt::WebViewNavigationCompletedEventArgs const& /*args*/) {
108
     void ReactWebView::OnNavigationCompleted(winrt::WebView const& webView, winrt::WebViewNavigationCompletedEventArgs const& /*args*/) {
113
             });
116
             });
114
 
117
 
115
         winrt::hstring windowAlert = L"window.alert = function (msg) {window.external.notify(`{\"type\":\"__alert\",\"message\":\"${msg}\"}`)};";
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
     void ReactWebView::OnNavigationFailed(winrt::IInspectable const& /*sender*/, winrt::WebViewNavigationFailedEventArgs const& args) {
129
     void ReactWebView::OnNavigationFailed(winrt::IInspectable const& /*sender*/, winrt::WebViewNavigationFailedEventArgs const& args) {

+ 1
- 3
windows/WebViewBridge/WebBridge.cpp Parādīt failu

20
 }
20
 }
21
 
21
 
22
 void WebBridge::PostMessage(int message) {
22
 void WebBridge::PostMessage(int message) {
23
-
24
-  
25
   m_dispatcher->RunAsync(
23
   m_dispatcher->RunAsync(
26
     CoreDispatcherPriority::Normal,
24
     CoreDispatcherPriority::Normal,
27
     ref new DispatchedHandler([this, message]
25
     ref new DispatchedHandler([this, message]
28
       {
26
       {
27
+        OutputDebugStringW(L"> WebBridge sending MessagePostedEvent");
29
         MessagePostedEvent(message);
28
         MessagePostedEvent(message);
30
       }));
29
       }));
31
-  
32
 }
30
 }