Keine Beschreibung

ReactWebView.h 2.2KB

12345678910111213141516171819202122232425262728293031323334353637
  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. namespace winrt::ReactNativeWebView::implementation {
  8. class ReactWebView : public ReactWebViewT<ReactWebView> {
  9. public:
  10. ReactWebView(Microsoft::ReactNative::IReactContext const& reactContext);
  11. winrt::Windows::UI::Xaml::Controls::WebView GetView();
  12. void PostMessage(winrt::hstring const& message);
  13. private:
  14. winrt::Windows::UI::Xaml::Controls::WebView m_webView{ nullptr };
  15. Microsoft::ReactNative::IReactContext m_reactContext{ nullptr };
  16. winrt::Windows::UI::Xaml::Controls::WebView::NavigationStarting_revoker m_navigationStartingRevoker{};
  17. winrt::Windows::UI::Xaml::Controls::WebView::NavigationCompleted_revoker m_navigationCompletedRevoker{};
  18. winrt::Windows::UI::Xaml::Controls::WebView::NavigationFailed_revoker m_navigationFailedRevoker{};
  19. winrt::Windows::UI::Xaml::Controls::WebView::ScriptNotify_revoker m_scriptNotifyRevoker{};
  20. void RegisterEvents();
  21. void WriteWebViewNavigationEventArg(winrt::Microsoft::ReactNative::IJSValueWriter const& eventDataWriter);
  22. void OnNavigationStarting(winrt::Windows::UI::Xaml::Controls::WebView const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationStartingEventArgs const& args);
  23. void OnNavigationCompleted(winrt::Windows::UI::Xaml::Controls::WebView const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationCompletedEventArgs const& args);
  24. void OnNavigationFailed(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationFailedEventArgs const& args);
  25. void OnScriptNotify(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::NotifyEventArgs const& args);
  26. };
  27. } // namespace winrt::ReactNativeWebView::implementation
  28. namespace winrt::ReactNativeWebView::factory_implementation {
  29. struct ReactWebView : ReactWebViewT<ReactWebView, implementation::ReactWebView> {};
  30. } // namespace winrt::ReactNativeWebView::factory_implementation