No Description

ReactWebView.h 2.3KB

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