Bladeren bron

PostMessage api uses string message

Tero Paananen 4 jaren geleden
bovenliggende
commit
75a2bebbe4

+ 5
- 7
windows/ReactNativeWebView/ReactWebView.cpp Bestand weergeven

95
         if (m_messagingEnabled) {
95
         if (m_messagingEnabled) {
96
           auto tag = this->GetValue(winrt::FrameworkElement::TagProperty()).as<winrt::IPropertyValue>().GetInt64();
96
           auto tag = this->GetValue(winrt::FrameworkElement::TagProperty()).as<winrt::IPropertyValue>().GetInt64();
97
           m_webBridge = WebViewBridge::WebBridge(tag);
97
           m_webBridge = WebViewBridge::WebBridge(tag);
98
-          m_message_token = m_webBridge.MessagePostedEvent([this](const int32_t& message) {
98
+          m_message_token = m_webBridge.MessagePostedEvent([this](hstring const& message) {
99
             this->OnMessagePosted(message);
99
             this->OnMessagePosted(message);
100
           });
100
           });
101
-          webView.AddWebAllowedObject(L"__RN_WEBVIEW_JS_BRIDGE", m_webBridge);
101
+          webView.AddWebAllowedObject(L"__REACT_WEB_VIEW_BRIDGE", m_webBridge);
102
         }
102
         }
103
     }
103
     }
104
 
104
 
105
-    void ReactWebView::OnMessagePosted(const int32_t& message)
105
+    void ReactWebView::OnMessagePosted(hstring const& message)
106
     {
106
     {
107
       OutputDebugStringW(L"> ReactWebView:OnMessagePosted received \n");
107
       OutputDebugStringW(L"> ReactWebView:OnMessagePosted received \n");
108
-
109
-      // TODO: send to RN
110
-      // PostMessage(winrt::hstring(args.Value()));
108
+      PostMessage(message);
111
     }
109
     }
112
 
110
 
113
     void ReactWebView::OnNavigationCompleted(winrt::WebView const& webView, winrt::WebViewNavigationCompletedEventArgs const& /*args*/) {
111
     void ReactWebView::OnNavigationCompleted(winrt::WebView const& webView, winrt::WebViewNavigationCompletedEventArgs const& /*args*/) {
122
 
120
 
123
         winrt::hstring windowAlert = L"window.alert = function (msg) {window.external.notify(`{\"type\":\"__alert\",\"message\":\"${msg}\"}`)};";
121
         winrt::hstring windowAlert = L"window.alert = function (msg) {window.external.notify(`{\"type\":\"__alert\",\"message\":\"${msg}\"}`)};";
124
         if (m_messagingEnabled) {
122
         if (m_messagingEnabled) {
125
-          winrt::hstring postMessage = L"window.ReactNativeWebView = {postMessage: function (data) {__RN_WEBVIEW_JS_BRIDGE.postMessage(String(data))}};";
123
+          winrt::hstring postMessage = L"window.ReactNativeWebView = {postMessage: function (data) {__REACT_WEB_VIEW_BRIDGE.postMessage(String(data))}};";
126
           webView.InvokeScriptAsync(L"eval", { windowAlert + postMessage });
124
           webView.InvokeScriptAsync(L"eval", { windowAlert + postMessage });
127
         }
125
         }
128
         else {
126
         else {

+ 1
- 1
windows/ReactNativeWebView/ReactWebView.h Bestand weergeven

35
         void OnNavigationCompleted(winrt::Windows::UI::Xaml::Controls::WebView const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationCompletedEventArgs const& args);
35
         void OnNavigationCompleted(winrt::Windows::UI::Xaml::Controls::WebView const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationCompletedEventArgs const& args);
36
         void OnNavigationFailed(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationFailedEventArgs const& args);
36
         void OnNavigationFailed(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationFailedEventArgs const& args);
37
         void OnScriptNotify(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::NotifyEventArgs const& args);
37
         void OnScriptNotify(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::NotifyEventArgs const& args);
38
-        void OnMessagePosted(const int32_t& message);
38
+        void OnMessagePosted(hstring const& message);
39
     };
39
     };
40
 } // namespace winrt::ReactNativeWebView::implementation
40
 } // namespace winrt::ReactNativeWebView::implementation
41
 
41
 

+ 1
- 1
windows/WebViewBridge/WebBridge.cpp Bestand weergeven

15
   m_dispatcher = Windows::UI::Core::CoreWindow::GetForCurrentThread()->Dispatcher;
15
   m_dispatcher = Windows::UI::Core::CoreWindow::GetForCurrentThread()->Dispatcher;
16
 }
16
 }
17
 
17
 
18
-void WebBridge::PostMessage(int message) {
18
+void WebBridge::PostMessage(Platform::String^ message) {
19
   m_dispatcher->RunAsync(
19
   m_dispatcher->RunAsync(
20
     CoreDispatcherPriority::Normal,
20
     CoreDispatcherPriority::Normal,
21
     ref new DispatchedHandler([this, message]
21
     ref new DispatchedHandler([this, message]

+ 2
- 2
windows/WebViewBridge/WebBridge.h Bestand weergeven

4
 
4
 
5
 namespace WebViewBridge
5
 namespace WebViewBridge
6
 {
6
 {
7
-  public delegate void MessagePosted(int message);
7
+  public delegate void MessagePosted(Platform::String^ message);
8
 
8
 
9
   [Windows::Foundation::Metadata::AllowForWebAttribute]
9
   [Windows::Foundation::Metadata::AllowForWebAttribute]
10
   public ref class WebBridge sealed
10
   public ref class WebBridge sealed
11
     {
11
     {
12
     public:
12
     public:
13
       WebBridge(int64 tag);
13
       WebBridge(int64 tag);
14
-      void PostMessage(int message);
14
+      void PostMessage(Platform::String^ message);
15
       event MessagePosted^ MessagePostedEvent;
15
       event MessagePosted^ MessagePostedEvent;
16
     private:
16
     private:
17
       Windows::UI::Core::CoreDispatcher^ m_dispatcher;
17
       Windows::UI::Core::CoreDispatcher^ m_dispatcher;