Explorar el Código

Store bridge as instance variable

Tero Paananen hace 4 años
padre
commit
c1f6adebf2

+ 4
- 8
windows/ReactNativeWebView/ReactWebView.cpp Ver fichero

@@ -6,8 +6,6 @@
6 6
 #include "ReactWebView.h"
7 7
 #include "ReactWebView.g.cpp"
8 8
 
9
-#include "winrt/WebViewBridge.h"
10
-
11 9
 
12 10
 
13 11
 namespace winrt {
@@ -89,21 +87,19 @@ namespace winrt::ReactNativeWebView::implementation {
89 87
 
90 88
         if (m_messagingEnabled) {
91 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 92
             if (auto self = ref.get()) {
96 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 100
     void ReactWebView::OnMessagePosted(const int32_t& message)
105 101
     {
106
-
102
+      // TODO: send to RN
107 103
     }
108 104
 
109 105
     void ReactWebView::OnNavigationCompleted(winrt::WebView const& webView, winrt::WebViewNavigationCompletedEventArgs const& /*args*/) {

+ 3
- 0
windows/ReactNativeWebView/ReactWebView.h Ver fichero

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