Sfoglia il codice sorgente

Store bridge as instance variable

Tero Paananen 4 anni fa
parent
commit
c1f6adebf2

+ 4
- 8
windows/ReactNativeWebView/ReactWebView.cpp Vedi File

6
 #include "ReactWebView.h"
6
 #include "ReactWebView.h"
7
 #include "ReactWebView.g.cpp"
7
 #include "ReactWebView.g.cpp"
8
 
8
 
9
-#include "winrt/WebViewBridge.h"
10
-
11
 
9
 
12
 
10
 
13
 namespace winrt {
11
 namespace winrt {
89
 
87
 
90
         if (m_messagingEnabled) {
88
         if (m_messagingEnabled) {
91
           auto tag = this->GetValue(winrt::FrameworkElement::TagProperty()).as<winrt::IPropertyValue>().GetInt64();
89
           auto tag = this->GetValue(winrt::FrameworkElement::TagProperty()).as<winrt::IPropertyValue>().GetInt64();
92
-
93
-          auto bridge = WebViewBridge::WebBridge(tag);
94
-          bridge.MessagePostedEvent(winrt::auto_revoke, [ref = get_weak()](const int32_t& message) {
90
+          m_webBridge = WebViewBridge::WebBridge(tag);
91
+          m_webBridge.MessagePostedEvent(winrt::auto_revoke, [ref = get_weak()](const int32_t& message) {
95
             if (auto self = ref.get()) {
92
             if (auto self = ref.get()) {
96
               self->OnMessagePosted(message);
93
               self->OnMessagePosted(message);
97
             }
94
             }
98
           });
95
           });
99
-
100
-          webView.AddWebAllowedObject(L"__RN_WEBVIEW_JS_BRIDGE", bridge);
96
+          webView.AddWebAllowedObject(L"__RN_WEBVIEW_JS_BRIDGE", m_webBridge);
101
         }
97
         }
102
     }
98
     }
103
 
99
 
104
     void ReactWebView::OnMessagePosted(const int32_t& message)
100
     void ReactWebView::OnMessagePosted(const int32_t& message)
105
     {
101
     {
106
-
102
+      // TODO: send to RN
107
     }
103
     }
108
 
104
 
109
     void ReactWebView::OnNavigationCompleted(winrt::WebView const& webView, winrt::WebViewNavigationCompletedEventArgs const& /*args*/) {
105
     void ReactWebView::OnNavigationCompleted(winrt::WebView const& webView, winrt::WebViewNavigationCompletedEventArgs const& /*args*/) {

+ 3
- 0
windows/ReactNativeWebView/ReactWebView.h Vedi File

7
 #include "NativeModules.h"
7
 #include "NativeModules.h"
8
 #include "ReactWebView.g.h"
8
 #include "ReactWebView.g.h"
9
 
9
 
10
+#include "winrt/WebViewBridge.h"
11
+
10
 namespace winrt::ReactNativeWebView::implementation {
12
 namespace winrt::ReactNativeWebView::implementation {
11
 
13
 
12
     class ReactWebView : public ReactWebViewT<ReactWebView> {
14
     class ReactWebView : public ReactWebViewT<ReactWebView> {
19
         bool m_messagingEnabled{ false };
21
         bool m_messagingEnabled{ false };
20
         winrt::Windows::UI::Xaml::Controls::WebView m_webView{ nullptr };
22
         winrt::Windows::UI::Xaml::Controls::WebView m_webView{ nullptr };
21
         Microsoft::ReactNative::IReactContext m_reactContext{ nullptr };
23
         Microsoft::ReactNative::IReactContext m_reactContext{ nullptr };
24
+        WebViewBridge::WebBridge m_webBridge{ nullptr };
22
         winrt::Windows::UI::Xaml::Controls::WebView::NavigationStarting_revoker m_navigationStartingRevoker{};
25
         winrt::Windows::UI::Xaml::Controls::WebView::NavigationStarting_revoker m_navigationStartingRevoker{};
23
         winrt::Windows::UI::Xaml::Controls::WebView::NavigationCompleted_revoker m_navigationCompletedRevoker{};
26
         winrt::Windows::UI::Xaml::Controls::WebView::NavigationCompleted_revoker m_navigationCompletedRevoker{};
24
         winrt::Windows::UI::Xaml::Controls::WebView::NavigationFailed_revoker m_navigationFailedRevoker{};
27
         winrt::Windows::UI::Xaml::Controls::WebView::NavigationFailed_revoker m_navigationFailedRevoker{};