瀏覽代碼

Add messagingEnabled prop

Tero Paananen 4 年之前
父節點
當前提交
82fc0fd3d3

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

@@ -142,4 +142,8 @@ namespace winrt::ReactNativeWebView::implementation {
142 142
             });
143 143
     }
144 144
 
145
+    void ReactWebView::SetMessagingEnabled(bool enabled) {
146
+      this->m_messagingEnabled = enabled;
147
+    }
148
+
145 149
 } // namespace winrt::ReactNativeWebView::implementation

+ 2
- 0
windows/ReactNativeWebView/ReactWebView.h 查看文件

@@ -13,8 +13,10 @@ namespace winrt::ReactNativeWebView::implementation {
13 13
     public:
14 14
         ReactWebView(Microsoft::ReactNative::IReactContext const& reactContext);
15 15
         void PostMessage(winrt::hstring const& message);
16
+        void SetMessagingEnabled(bool enabled);
16 17
 
17 18
     private:
19
+        bool m_messagingEnabled{ false };
18 20
         winrt::Windows::UI::Xaml::Controls::WebView m_webView{ nullptr };
19 21
         Microsoft::ReactNative::IReactContext m_reactContext{ nullptr };
20 22
         winrt::Windows::UI::Xaml::Controls::WebView::NavigationStarting_revoker m_navigationStartingRevoker{};

+ 1
- 0
windows/ReactNativeWebView/ReactWebView.idl 查看文件

@@ -3,5 +3,6 @@ namespace ReactNativeWebView{
3 3
     runtimeclass ReactWebView : Windows.UI.Xaml.Controls.UserControl{
4 4
         ReactWebView(Microsoft.ReactNative.IReactContext context);
5 5
         void PostMessage(String message);
6
+        void SetMessagingEnabled(Boolean enabled);
6 7
     };
7 8
 } // namespace ReactNativeWebView

+ 8
- 0
windows/ReactNativeWebView/ReactWebViewManager.cpp 查看文件

@@ -40,6 +40,8 @@ namespace winrt::ReactNativeWebView::implementation {
40 40
     IMapView<hstring, ViewManagerPropertyType> ReactWebViewManager::NativeProps() noexcept {
41 41
         auto nativeProps = winrt::single_threaded_map<hstring, ViewManagerPropertyType>();
42 42
         nativeProps.Insert(L"source", ViewManagerPropertyType::Map);
43
+        nativeProps.Insert(L"backgroundColor", ViewManagerPropertyType::Color); // Does this really work?
44
+        nativeProps.Insert(L"messagingEnabled", ViewManagerPropertyType::Boolean);
43 45
         return nativeProps.GetView();
44 46
     }
45 47
 
@@ -84,6 +86,12 @@ namespace winrt::ReactNativeWebView::implementation {
84 86
                     auto color = propertyValue.To<winrt::Color>();
85 87
                     webView.DefaultBackgroundColor(color.A==0 ? winrt::Colors::Transparent() : color);
86 88
                 }
89
+                else if (propertyName == "messagingEnabled") {
90
+                  auto messagingEnabled = propertyValue.To<bool>();
91
+                  if (auto reactWebView = content.try_as<ReactNativeWebView::ReactWebView>()) {
92
+                    reactWebView.SetMessagingEnabled(messagingEnabled);
93
+                  }
94
+                }
87 95
             }
88 96
         }
89 97
     }