Нет описания

ReactWebView.h 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Licensed under the MIT License.
  3. #pragma once
  4. #include "winrt/Microsoft.ReactNative.h"
  5. #include "NativeModules.h"
  6. #include "ReactWebView.g.h"
  7. #include "winrt/WebViewBridgeComponent.h"
  8. using namespace winrt::WebViewBridgeComponent;
  9. namespace winrt::ReactNativeWebView::implementation {
  10. class ReactWebView : public ReactWebViewT<ReactWebView> {
  11. public:
  12. ReactWebView(Microsoft::ReactNative::IReactContext const& reactContext);
  13. void PostMessage(winrt::hstring const& message);
  14. void SetMessagingEnabled(bool enabled);
  15. ~ReactWebView();
  16. private:
  17. bool m_messagingEnabled{ true };
  18. winrt::Windows::UI::Xaml::Controls::WebView m_webView{ nullptr };
  19. Microsoft::ReactNative::IReactContext m_reactContext{ nullptr };
  20. WebBridge m_webBridge{ nullptr };
  21. winrt::event_token m_message_token;
  22. winrt::Windows::UI::Xaml::Controls::WebView::NavigationStarting_revoker m_navigationStartingRevoker{};
  23. winrt::Windows::UI::Xaml::Controls::WebView::NavigationCompleted_revoker m_navigationCompletedRevoker{};
  24. winrt::Windows::UI::Xaml::Controls::WebView::NavigationFailed_revoker m_navigationFailedRevoker{};
  25. void RegisterEvents();
  26. void WriteWebViewNavigationEventArg(winrt::Windows::UI::Xaml::Controls::WebView const& sender, winrt::Microsoft::ReactNative::IJSValueWriter const& eventDataWriter);
  27. void OnNavigationStarting(winrt::Windows::UI::Xaml::Controls::WebView const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationStartingEventArgs const& args);
  28. void OnNavigationCompleted(winrt::Windows::UI::Xaml::Controls::WebView const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationCompletedEventArgs const& args);
  29. void OnNavigationFailed(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationFailedEventArgs const& args);
  30. void OnMessagePosted(hstring const& message);
  31. };
  32. } // namespace winrt::ReactNativeWebView::implementation
  33. namespace winrt::ReactNativeWebView::factory_implementation {
  34. struct ReactWebView : ReactWebViewT<ReactWebView, implementation::ReactWebView> {};
  35. } // namespace winrt::ReactNativeWebView::factory_implementation