浏览代码

Store bridge as instance variable

Tero Paananen 4 年前
父节点
当前提交
c1f6adebf2
共有 2 个文件被更改,包括 7 次插入8 次删除
  1. 4
    8
      windows/ReactNativeWebView/ReactWebView.cpp
  2. 3
    0
      windows/ReactNativeWebView/ReactWebView.h

+ 4
- 8
windows/ReactNativeWebView/ReactWebView.cpp 查看文件

@@ -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 查看文件

@@ -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{};