Parcourir la source

PostMessage api uses string message

Tero Paananen il y a 4 ans
Parent
révision
75a2bebbe4

+ 5
- 7
windows/ReactNativeWebView/ReactWebView.cpp Voir le fichier

@@ -95,19 +95,17 @@ namespace winrt::ReactNativeWebView::implementation {
95 95
         if (m_messagingEnabled) {
96 96
           auto tag = this->GetValue(winrt::FrameworkElement::TagProperty()).as<winrt::IPropertyValue>().GetInt64();
97 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 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 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 111
     void ReactWebView::OnNavigationCompleted(winrt::WebView const& webView, winrt::WebViewNavigationCompletedEventArgs const& /*args*/) {
@@ -122,7 +120,7 @@ namespace winrt::ReactNativeWebView::implementation {
122 120
 
123 121
         winrt::hstring windowAlert = L"window.alert = function (msg) {window.external.notify(`{\"type\":\"__alert\",\"message\":\"${msg}\"}`)};";
124 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 124
           webView.InvokeScriptAsync(L"eval", { windowAlert + postMessage });
127 125
         }
128 126
         else {

+ 1
- 1
windows/ReactNativeWebView/ReactWebView.h Voir le fichier

@@ -35,7 +35,7 @@ namespace winrt::ReactNativeWebView::implementation {
35 35
         void OnNavigationCompleted(winrt::Windows::UI::Xaml::Controls::WebView const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationCompletedEventArgs const& args);
36 36
         void OnNavigationFailed(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationFailedEventArgs const& args);
37 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 40
 } // namespace winrt::ReactNativeWebView::implementation
41 41
 

+ 1
- 1
windows/WebViewBridge/WebBridge.cpp Voir le fichier

@@ -15,7 +15,7 @@ WebBridge::WebBridge(int64 tag)
15 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 19
   m_dispatcher->RunAsync(
20 20
     CoreDispatcherPriority::Normal,
21 21
     ref new DispatchedHandler([this, message]

+ 2
- 2
windows/WebViewBridge/WebBridge.h Voir le fichier

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