Browse Source

Add messagingEnabled prop

Tero Paananen 4 years ago
parent
commit
82fc0fd3d3

+ 4
- 0
windows/ReactNativeWebView/ReactWebView.cpp View File

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

+ 2
- 0
windows/ReactNativeWebView/ReactWebView.h View File

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

+ 1
- 0
windows/ReactNativeWebView/ReactWebView.idl View File

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

+ 8
- 0
windows/ReactNativeWebView/ReactWebViewManager.cpp View File

40
     IMapView<hstring, ViewManagerPropertyType> ReactWebViewManager::NativeProps() noexcept {
40
     IMapView<hstring, ViewManagerPropertyType> ReactWebViewManager::NativeProps() noexcept {
41
         auto nativeProps = winrt::single_threaded_map<hstring, ViewManagerPropertyType>();
41
         auto nativeProps = winrt::single_threaded_map<hstring, ViewManagerPropertyType>();
42
         nativeProps.Insert(L"source", ViewManagerPropertyType::Map);
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
         return nativeProps.GetView();
45
         return nativeProps.GetView();
44
     }
46
     }
45
 
47
 
84
                     auto color = propertyValue.To<winrt::Color>();
86
                     auto color = propertyValue.To<winrt::Color>();
85
                     webView.DefaultBackgroundColor(color.A==0 ? winrt::Colors::Transparent() : color);
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
     }