Nav apraksta

ReactWebView.h 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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/WebViewBridge.h"
  8. namespace winrt::ReactNativeWebView::implementation {
  9. class ReactWebView : public ReactWebViewT<ReactWebView> {
  10. public:
  11. ReactWebView(Microsoft::ReactNative::IReactContext const& reactContext);
  12. void PostMessage(winrt::hstring const& message);
  13. void SetMessagingEnabled(bool enabled);
  14. ~ReactWebView();
  15. private:
  16. bool m_messagingEnabled{ true };
  17. winrt::Windows::UI::Xaml::Controls::WebView m_webView{ nullptr };
  18. Microsoft::ReactNative::IReactContext m_reactContext{ nullptr };
  19. WebViewBridge::WebBridge m_webBridge{ nullptr };
  20. winrt::event_token m_message_token;
  21. winrt::Windows::UI::Xaml::Controls::WebView::NavigationStarting_revoker m_navigationStartingRevoker{};
  22. winrt::Windows::UI::Xaml::Controls::WebView::NavigationCompleted_revoker m_navigationCompletedRevoker{};
  23. winrt::Windows::UI::Xaml::Controls::WebView::NavigationFailed_revoker m_navigationFailedRevoker{};
  24. void RegisterEvents();
  25. void WriteWebViewNavigationEventArg(winrt::Windows::UI::Xaml::Controls::WebView const& sender, winrt::Microsoft::ReactNative::IJSValueWriter const& eventDataWriter);
  26. void OnNavigationStarting(winrt::Windows::UI::Xaml::Controls::WebView const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationStartingEventArgs const& args);
  27. void OnNavigationCompleted(winrt::Windows::UI::Xaml::Controls::WebView const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationCompletedEventArgs const& args);
  28. void OnNavigationFailed(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationFailedEventArgs const& args);
  29. void OnMessagePosted(hstring const& message);
  30. };
  31. } // namespace winrt::ReactNativeWebView::implementation
  32. namespace winrt::ReactNativeWebView::factory_implementation {
  33. struct ReactWebView : ReactWebViewT<ReactWebView, implementation::ReactWebView> {};
  34. } // namespace winrt::ReactNativeWebView::factory_implementation