react-native-webview.git

ReactWebViewManager.h 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. namespace winrt::ReactNativeWebView::implementation {
  7. class ReactWebViewManager : public winrt::implements<
  8. ReactWebViewManager,
  9. winrt::Microsoft::ReactNative::IViewManager,
  10. winrt::Microsoft::ReactNative::IViewManagerWithReactContext,
  11. winrt::Microsoft::ReactNative::IViewManagerWithNativeProperties,
  12. winrt::Microsoft::ReactNative::IViewManagerWithExportedEventTypeConstants,
  13. winrt::Microsoft::ReactNative::IViewManagerWithCommands> {
  14. public:
  15. ReactWebViewManager();
  16. // IViewManager
  17. winrt::hstring Name() noexcept;
  18. winrt::Windows::UI::Xaml::FrameworkElement CreateView() noexcept;
  19. // IViewManagerWithReactContext
  20. winrt::Microsoft::ReactNative::IReactContext ReactContext() noexcept;
  21. void ReactContext(winrt::Microsoft::ReactNative::IReactContext reactContext) noexcept;
  22. // IViewManagerWithNativeProperties
  23. winrt::Windows::Foundation::Collections::
  24. IMapView<winrt::hstring, winrt::Microsoft::ReactNative::ViewManagerPropertyType>
  25. NativeProps() noexcept;
  26. void UpdateProperties(
  27. winrt::Windows::UI::Xaml::FrameworkElement const& view,
  28. winrt::Microsoft::ReactNative::IJSValueReader const& propertyMapReader) noexcept;
  29. // IViewManagerWithExportedEventTypeConstants
  30. winrt::Microsoft::ReactNative::ConstantProvider ExportedCustomBubblingEventTypeConstants() noexcept;
  31. winrt::Microsoft::ReactNative::ConstantProvider ExportedCustomDirectEventTypeConstants() noexcept;
  32. // IViewManagerWithCommands
  33. winrt::Windows::Foundation::Collections::IMapView<winrt::hstring, int64_t> Commands() noexcept;
  34. void DispatchCommand(
  35. winrt::Windows::UI::Xaml::FrameworkElement const& view,
  36. int64_t commandId,
  37. winrt::Microsoft::ReactNative::IJSValueReader const& commandArgsReader) noexcept;
  38. private:
  39. winrt::weak_ref<winrt::Windows::UI::Xaml::Controls::WebView> m_webView;
  40. winrt::Microsoft::ReactNative::IReactContext m_reactContext{ nullptr };
  41. winrt::Windows::UI::Xaml::Controls::WebView::NavigationCompleted_revoker m_navigationCompletedRevoker{};
  42. void RegisterEvents();
  43. void SetSource(winrt::Windows::Foundation::Uri const& uri);
  44. void OnNavigationCompleted(winrt::Windows::UI::Xaml::Controls::WebView const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationCompletedEventArgs const& args);
  45. };
  46. } // namespace winrt::ReactWebView::implementation